Skip to content

Incorrect validation of #[\Attribute]’s first parameter #13970

Closed
@TimWolla

Description

@TimWolla

Description

The following code:

<?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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions