Skip to content

Commit f3d7f32

Browse files
Andrew Menino-Barlowfabpot
Andrew Menino-Barlow
authored andcommitted
Add #[NoDiscard] to the PHP 8.5 polyfill
1 parent 4f6ee63 commit f3d7f32

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Polyfills are provided for:
7373
- the `mb_trim`, `mb_ltrim` and `mb_rtrim` functions introduced in PHP 8.4;
7474
- the `CURL_HTTP_VERSION_3` and `CURL_HTTP_VERSION_3ONLY` constants introduced in PHP 8.4;
7575
- the `get_error_handler` and `get_exception_handler` functions introduced in PHP 8.5;
76+
- the `NoDiscard` attribute introduced in PHP 8.5;
7677

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

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"src/Intl/Icu/Resources/stubs",
6464
"src/Intl/MessageFormatter/Resources/stubs",
6565
"src/Intl/Normalizer/Resources/stubs",
66+
"src/Php85/Resources/stubs",
6667
"src/Php84/Resources/stubs",
6768
"src/Php83/Resources/stubs",
6869
"src/Php82/Resources/stubs",

src/Php85/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Symfony Polyfill / Php85
44
This component provides features added to PHP 8.5 core:
55

66
- [`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)
78

89
More information can be found in the
910
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
}

src/Php85/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
},
2121
"autoload": {
2222
"psr-4": { "Symfony\\Polyfill\\Php85\\": "" },
23-
"files": [ "bootstrap.php" ]
23+
"files": [ "bootstrap.php" ],
24+
"classmap": [ "Resources/stubs" ]
2425
},
2526
"minimum-stability": "dev",
2627
"extra": {

0 commit comments

Comments
 (0)