[php-src] Issue #8982: Valid attribute on methods break when read via ReflectionFunction

From: Date: Tue, 12 Jul 2022 12:21:56 +0000
Subject: [php-src] Issue #8982: Valid attribute on methods break when read via ReflectionFunction
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241910@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8982 Author: nicolas-grekas ### Description The following code: ```php #[Attribute(Attribute::TARGET_METHOD)] class A { } class B { #[A] public function m() { } } $a = new B(); $c = [$a, 'm']; $r = new ReflectionFunction($c(...)); var_dump($r->getAttributes()[0]->newInstance()); ``` Resulted in [this output](https://3v4l.org/fepGP): ``` Fatal error: Uncaught Error: Attribute "A" cannot target function (allowed targets: method) ``` But I expected this output instead: ``` object(A)#5 (0) { } ``` ### PHP Version PHP >= 8.1.6 ### Operating System _No response_

« previous php.bugs (#241910) next »