├── Resources └── stubs │ ├── DelayedTargetValidation.php │ └── NoDiscard.php ├── README.md ├── bootstrap.php ├── composer.json ├── LICENSE └── Php85.php /Resources/stubs/DelayedTargetValidation.php: -------------------------------------------------------------------------------- 1 | 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 | if (\PHP_VERSION_ID < 80500) { 13 | // @author Daniel Scherzer 14 | #[Attribute(Attribute::TARGET_ALL)] 15 | final class DelayedTargetValidation 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Resources/stubs/NoDiscard.php: -------------------------------------------------------------------------------- 1 | 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 | if (\PHP_VERSION_ID < 80500) { 13 | #[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_FUNCTION)] 14 | final class NoDiscard 15 | { 16 | public ?string $message; 17 | 18 | public function __construct(?string $message = null) 19 | { 20 | $this->message = $message; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Symfony Polyfill / Php85 2 | ======================== 3 | 4 | This component provides features added to PHP 8.5 core: 5 | 6 | - [`get_error_handler` and `get_exception_handler`](https://wiki.php.net/rfc/get-error-exception-handler) 7 | - [`NoDiscard`](https://wiki.php.net/rfc/marking_return_value_as_important) 8 | - [`array_first` and `array_last`](https://wiki.php.net/rfc/array_first_last) 9 | - [`DelayedTargetValidation`](https://wiki.php.net/rfc/delayedtargetvalidation_attribute) 10 | 11 | More information can be found in the 12 | [main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md). 13 | 14 | License 15 | ======= 16 | 17 | This library is released under the [MIT license](LICENSE). 18 | -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | 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 | use Symfony\Polyfill\Php85 as p; 13 | 14 | if (\PHP_VERSION_ID >= 80500) { 15 | return; 16 | } 17 | 18 | if (!function_exists('get_error_handler')) { 19 | function get_error_handler(): ?callable { return p\Php85::get_error_handler(); } 20 | } 21 | 22 | if (!function_exists('get_exception_handler')) { 23 | function get_exception_handler(): ?callable { return p\Php85::get_exception_handler(); } 24 | } 25 | 26 | if (!function_exists('array_first')) { 27 | function array_first(array $array) { return p\Php85::array_first($array); } 28 | } 29 | 30 | if (!function_exists('array_last')) { 31 | function array_last(array $array) { return p\Php85::array_last($array); } 32 | } 33 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "symfony/polyfill-php85", 3 | "type": "library", 4 | "description": "Symfony polyfill backporting some PHP 8.5+ features to lower PHP versions", 5 | "keywords": ["polyfill", "shim", "compatibility", "portable"], 6 | "homepage": "https://symfony.com", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Nicolas Grekas", 11 | "email": "p@tchwork.com" 12 | }, 13 | { 14 | "name": "Symfony Community", 15 | "homepage": "https://symfony.com/contributors" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=7.2" 20 | }, 21 | "autoload": { 22 | "psr-4": { "Symfony\\Polyfill\\Php85\\": "" }, 23 | "files": [ "bootstrap.php" ], 24 | "classmap": [ "Resources/stubs" ] 25 | }, 26 | "minimum-stability": "dev", 27 | "extra": { 28 | "thanks": { 29 | "name": "symfony/polyfill", 30 | "url": "https://github.com/symfony/polyfill" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2025-present Fabien Potencier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Php85.php: -------------------------------------------------------------------------------- 1 | 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 Symfony\Polyfill\Php85; 13 | 14 | /** 15 | * @author Pierre Ambroise 16 | * 17 | * @internal 18 | */ 19 | final class Php85 20 | { 21 | public static function get_error_handler(): ?callable 22 | { 23 | $handler = set_error_handler(null); 24 | restore_error_handler(); 25 | 26 | return $handler; 27 | } 28 | 29 | public static function get_exception_handler(): ?callable 30 | { 31 | $handler = set_exception_handler(null); 32 | restore_exception_handler(); 33 | 34 | return $handler; 35 | } 36 | 37 | public static function array_first(array $array) 38 | { 39 | foreach ($array as $value) { 40 | return $value; 41 | } 42 | 43 | return null; 44 | } 45 | 46 | public static function array_last(array $array) 47 | { 48 | return $array ? current(array_slice($array, -1)) : null; 49 | } 50 | } 51 | --------------------------------------------------------------------------------