Skip to content

Commit 6fedf31

Browse files
Andrew Menino-Barlowfabpot
authored andcommitted
Add #[NoDiscard] to the PHP 8.5 polyfill
1 parent 4850799 commit 6fedf31

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
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).

Resources/stubs/NoDiscard.php

Lines changed: 23 additions & 0 deletions
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 <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+
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+
}

composer.json

Lines changed: 2 additions & 1 deletion
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)