[php-src] Issue #13970: Incorrect validation of #[\Attribute]’s first parameter
| From: | TimWolla | Date: | Mon, 15 Apr 2024 13:51:13 +0000 |
| Subject: | [php-src] Issue #13970: Incorrect validation of #[\Attribute]’s first parameter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246762@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13970
Author: TimWolla
### Description
The following code:
```php
<?php
#[Attribute(Random\IntervalBoundary::ClosedOpen)]
class Foo {
}
#[Foo]
function test1() {
}
$reflection = new ReflectionFunction('test1');
var_dump($reflection->getAttributes()[0]->newInstance());
?>
```
Resulted in this output:
```
Fatal error: Uncaught Error: Attribute "Foo" cannot target function (allowed targets: ) in
php-src/test.php:13
Stack trace:
#0 php-src/test.php(13): ReflectionAttribute->newInstance()
#1 {main}
thrown in php-src/test.php on line 13
[Mon Apr 15 15:49:24 2024] Script: 'php-src/test.php'
php-src/Zend/zend_objects.c(189) : Freeing 0x000073dc9105c780 (56 bytes), script=php-src/test.php
=== Total 1 memory leaks detected ===
```
But I expected this output instead:
1. No memory leak.
2. Something related to the argument not being a correct integer.
### PHP Version
git master
### Operating System
Ubuntu 23.10