PHP 8.5.8 Released!

Filter\FilterFailedException クラス

(No version information available, might only be in Git)

はじめに

検証フィルタが失敗し、かつ FILTER_THROW_ON_FAILURE フラグが設定されている場合にスローされます。

クラス概要

namespace Filter;
class FilterFailedException extends Filter\FilterException {
/* 継承したプロパティ */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* 継承したメソッド */
public function Exception::__construct(string $message = "", int $code = 0, ?Throwable $previous = null)
final public function Exception::getMessage(): string
final public function Exception::getPrevious(): ?Throwable
final public function Exception::getCode(): int
final public function Exception::getFile(): string
final public function Exception::getLine(): int
final public function Exception::getTrace(): array
final public function Exception::getTraceAsString(): string
public function Exception::__toString(): string
private function Exception::__clone(): void
}
add a note

User Contributed Notes 1 note

up
0
masakielastic at gmail dot com
1 day ago
Filter\FilterFailedException is thrown when a validation filter fails and FILTER_THROW_ON_FAILURE is set.

<?php

try {
    $email = filter_var(
        'not an email',
        FILTER_VALIDATE_EMAIL,
        FILTER_THROW_ON_FAILURE
    );
} catch (Filter\FilterFailedException $e) {
    echo "The value did not pass validation.\n";
}

This exception represents validation failure, not an unknown filter. If the filter ID itself comes from a name or configuration, check it separately before calling filter_var():

<?php

$filter = filter_id('validate_email');

if ($filter === false) {
    throw new InvalidArgumentException('Unknown filter.');
}

try {
    $email = filter_var(
        'not an email',
        $filter,
        FILTER_THROW_ON_FAILURE
    );
} catch (Filter\FilterFailedException $e) {
    echo "The value did not pass validation.\n";
}
To Top