Updated PHP Windows builds for Brotli security fix

La classe Filter\FilterFailedException

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

Introduction

Lancée lorsqu'un filtre de validation échoue et que le drapeau FILTER_THROW_ON_FAILURE est défini.

Synopsis de la classe

namespace Filter;
class FilterFailedException extends Filter\FilterException {
/* Propriétés héritées */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* Méthodes héritées */
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
3 months 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