-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
Description
A function turned into a callable has its ReflectionFunction::getClosureCalledClass()
return the class around, while ::getClosureScopeClass()
returns null
.
Give that a function doesn't have any class context, ::getClosureCalledClass()
should also return null.
The following code:
<?php
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class Attr {
public function __construct(public Closure $value) {}
}
#[Attr(self::myMethod(...))]
#[Attr(strrev(...))]
#[Attr(static function ($value) {
return \strtoupper($value);
})]
class C {
private static function myMethod(string $foo) {
return "XXX";
}
}
foreach ((new ReflectionClass(C::class))->getAttributes() as $reflectionAttribute) {
$a = $reflectionAttribute->newInstance();
$r = new \ReflectionFunction($a->value);
var_dump($r->getClosureCalledClass());
var_dump($r->getClosureScopeClass());
}
Resulted in this output:
object(ReflectionClass)#9 (1) {
["name"]=>
string(1) "C"
}
object(ReflectionClass)#9 (1) {
["name"]=>
string(1) "C"
}
object(ReflectionClass)#8 (1) {
["name"]=>
string(1) "C"
}
NULL
object(ReflectionClass)#7 (1) {
["name"]=>
string(1) "C"
}
object(ReflectionClass)#7 (1) {
["name"]=>
string(1) "C"
}
But I expected this output instead:
object(ReflectionClass)#9 (1) {
["name"]=>
string(1) "C"
}
object(ReflectionClass)#9 (1) {
["name"]=>
string(1) "C"
}
NULL
NULL
object(ReflectionClass)#7 (1) {
["name"]=>
string(1) "C"
}
object(ReflectionClass)#7 (1) {
["name"]=>
string(1) "C"
}
PHP Version
PHP 8.5 at least
Operating System
No response