Reflection Doesn’t Return Self¶
Reflection used to return the original self type, including its case. Since PHP 8.5, it is now returning the actual name of the class, instead of the relative type.
PHP code¶
<?php
// code from https://www.reddit.com/r/PHP/comments/1rd3j74/php_85_reflectionnamedtypegetname_change/
class Foo
{
function poop (self $a): self
{
}
}
$refMethod = new ReflectionMethod('Foo', 'poop');
$refParam = $refMethod->getParameters()[0];
print_r(array(
'paramType' => $refParam->getType()->getName(),
'returnType' => $refMethod->getReturnType()->getName(),
));
?>
Before¶
Array
(
[paramType] => self
[returnType] => self
)
After¶
Array
(
[paramType] => Foo
[returnType] => Foo
)
PHP version change¶
This behavior changed in 8.5