From fe39c79084e8510b2aaf34b27b36a42fe322dd4c Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Thu, 20 Nov 2025 05:00:34 +0700 Subject: [PATCH] [PHP 8.5] Add new `\Filter\FilterException` and `Filter\FilterFailedException` PHP 8.5 adds two new exception classes, along with the new `FILTER_THROW_ON_FAILURE` flag. We can not polyfill the exception behavior (which is activated with the `FILTER_THROW_ON_FAILURE` flag), but we can still polyfill the exception classes. - [RFC](https://wiki.php.net/rfc/filter_throw_on_failure) - [PR](https://github.com/php/php-src/pull/18896) - [`Filter\FilterException`](https://php.watch/versions/8.5/filter-validation-throw-exception#FilterException), [codex](https://php.watch/codex/Filter/FilterException) - [`Filter\FilterFailedException`](https://php.watch/versions/8.5/filter-validation-throw-exception#FilterFailedException), [codex](https://php.watch/codex/Filter/FilterFailedException) --- README.md | 2 ++ src/Php85/README.md | 2 ++ .../Resources/stubs/Filter/FilterException.php | 18 ++++++++++++++++++ .../stubs/Filter/FilterFailedException.php | 18 ++++++++++++++++++ tests/Php85/Php85Test.php | 6 ++++++ 5 files changed, 46 insertions(+) create mode 100644 src/Php85/Resources/stubs/Filter/FilterException.php create mode 100644 src/Php85/Resources/stubs/Filter/FilterFailedException.php diff --git a/README.md b/README.md index 60edd9a4..c10e4373 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ Polyfills are provided for: - the `NoDiscard` attribute introduced in PHP 8.5; - the `array_first` and `array_last` functions introduced in PHP 8.5; - the `DelayedTargetValidation` attribute introduced in PHP 8.5; +- the `Filter\FilterException` class introduced in PHP 8.5; +- the `Filter\FilterFailedException` class introduced in PHP 8.5; It is strongly recommended to upgrade your PHP version and/or install the missing extensions whenever possible. This polyfill should be used only when there is no diff --git a/src/Php85/README.md b/src/Php85/README.md index 6cac5666..ae0265ae 100644 --- a/src/Php85/README.md +++ b/src/Php85/README.md @@ -7,6 +7,8 @@ This component provides features added to PHP 8.5 core: - [`NoDiscard`](https://wiki.php.net/rfc/marking_return_value_as_important) - [`array_first` and `array_last`](https://wiki.php.net/rfc/array_first_last) - [`DelayedTargetValidation`](https://wiki.php.net/rfc/delayedtargetvalidation_attribute) +- [`Filter\FilterException class`](https://wiki.php.net/rfc/filter_throw_on_failure) +- [`Filter\FilterFailedException class`](https://wiki.php.net/rfc/filter_throw_on_failure) More information can be found in the [main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md). diff --git a/src/Php85/Resources/stubs/Filter/FilterException.php b/src/Php85/Resources/stubs/Filter/FilterException.php new file mode 100644 index 00000000..23f5220b --- /dev/null +++ b/src/Php85/Resources/stubs/Filter/FilterException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Filter; + +if (\PHP_VERSION_ID < 80500) { + class FilterException extends \Exception + { + } +} diff --git a/src/Php85/Resources/stubs/Filter/FilterFailedException.php b/src/Php85/Resources/stubs/Filter/FilterFailedException.php new file mode 100644 index 00000000..9668364c --- /dev/null +++ b/src/Php85/Resources/stubs/Filter/FilterFailedException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Filter; + +if (\PHP_VERSION_ID < 80500) { + class FilterFailedException extends FilterException + { + } +} diff --git a/tests/Php85/Php85Test.php b/tests/Php85/Php85Test.php index 1ff50bd8..b44d7cda 100644 --- a/tests/Php85/Php85Test.php +++ b/tests/Php85/Php85Test.php @@ -114,6 +114,12 @@ public function testArrayFirstArrayLast() $this->assertTrue(array_first([true, new \stdClass()])); $this->assertEquals(new \stdClass(), array_last([true, new \stdClass()])); } + + public function testFilterExceptionClassesExist() + { + $this->assertTrue(class_exists(\Filter\FilterException::class)); + $this->assertTrue(class_exists(\Filter\FilterFailedException::class)); + } } class TestHandler