Skip to content

Commit 22c1d63

Browse files
committed
[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](php/php-src#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)
1 parent 41ace00 commit 22c1d63

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Polyfills are provided for:
7979
- the `NoDiscard` attribute introduced in PHP 8.5;
8080
- the `array_first` and `array_last` functions introduced in PHP 8.5;
8181
- the `DelayedTargetValidation` attribute introduced in PHP 8.5;
82+
- the `Filter\FilterException` class introduced in PHP 8.5;
83+
- the `Filter\FilterFailedException` class introduced in PHP 8.5;
8284

8385
It is strongly recommended to upgrade your PHP version and/or install the missing
8486
extensions whenever possible. This polyfill should be used only when there is no

src/Php85/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This component provides features added to PHP 8.5 core:
77
- [`NoDiscard`](https://wiki.php.net/rfc/marking_return_value_as_important)
88
- [`array_first` and `array_last`](https://wiki.php.net/rfc/array_first_last)
99
- [`DelayedTargetValidation`](https://wiki.php.net/rfc/delayedtargetvalidation_attribute)
10+
- [`Filter\FilterException class`](https://wiki.php.net/rfc/filter_throw_on_failure)
11+
- [`Filter\FilterFailedException class`](https://wiki.php.net/rfc/filter_throw_on_failure)
1012

1113
More information can be found in the
1214
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Filter;
13+
14+
if (\PHP_VERSION_ID < 80500) {
15+
class FilterException extends Exception
16+
{
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Filter;
13+
14+
if (\PHP_VERSION_ID < 80500) {
15+
class FilterFailedException extends FilterException
16+
{
17+
}
18+
}

tests/Php85/Php85Test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public function testArrayFirstArrayLast()
114114
$this->assertTrue(array_first([true, new \stdClass()]));
115115
$this->assertEquals(new \stdClass(), array_last([true, new \stdClass()]));
116116
}
117+
118+
public function testFilterExceptionClassesExist()
119+
{
120+
$this->assertTrue(class_exists(\Filter\FilterException::class));
121+
$this->assertTrue(class_exists(\Filter\FilterFailedException::class));
122+
}
117123
}
118124

119125
class TestHandler

0 commit comments

Comments
 (0)