PHP 8.5.8 Released!

La clase Filter\FilterFailedException

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

Introducción

Lanzada cuando un filtro de validación falla y el indicador FILTER_THROW_ON_FAILURE está activado.

Sinopsis de la Clase

namespace Filter;
class FilterFailedException extends Filter\FilterException {
/* Propiedades heredadas */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* Métodos heredados */
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