Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_THROW_ON_FAILURE` constant introduced in PHP 8.5;
- the `\Filter\FilterException` and `\Filter\FilterFailedException` classes 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
Expand Down
2 changes: 2 additions & 0 deletions src/Php85/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_THROW_ON_FAILURE`, `\Filter\FilterException`, and
`\Filter\FilterFailedException` (see [RFC](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).
Expand Down
19 changes: 19 additions & 0 deletions src/Php85/Resources/stubs/Filter/FilterException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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) {
// @author Daniel Scherzer <daniel.e.scherzer@gmail.com>
class FilterException extends \Exception
{
}
}
19 changes: 19 additions & 0 deletions src/Php85/Resources/stubs/Filter/FilterFailedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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) {
// @author Daniel Scherzer <daniel.e.scherzer@gmail.com>
class FilterFailedException extends FilterException
{
}
}
4 changes: 4 additions & 0 deletions src/Php85/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ function array_first(array $array) { return p\Php85::array_first($array); }
if (!function_exists('array_last')) {
function array_last(array $array) { return p\Php85::array_last($array); }
}

if (!defined('FILTER_THROW_ON_FAILURE')) {
define('FILTER_THROW_ON_FAILURE', 0x10000000);
}
9 changes: 9 additions & 0 deletions tests/Php85/Php85Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ public function testArrayFirstArrayLast()
$this->assertTrue(array_first([true, new \stdClass()]));
$this->assertEquals(new \stdClass(), array_last([true, new \stdClass()]));
}

public function testFilterThrowFlagValue()
{
// Make sure that the polyfill matches the real value, as of the
// initial implementation in
// https://github.com/php/php-src/commit/0b326dcbabe11e227f911bbde967b74fcada9e5a
$this->assertTrue(defined('FILTER_THROW_ON_FAILURE'));
$this->assertSame(0x10000000, FILTER_THROW_ON_FAILURE);
}
}

class TestHandler
Expand Down
Loading