[php-src] Issue #21284: php 8.5 ReflectionType->getName no longer returns "self"
[email protected] (bkdotcom)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <zrqUGCLBAHdehTng3B9xgWTVZrswtOYbYunYnbsAYhQ@main.internal.php.net> |
Issue: https://github.com/php/php-src/issues/21284
Author: bkdotcom
### Description
The following code:
https://3v4l.org/5ACeW#v8.5.3
```php
<?php
class Bar
{
}
class Foo extends Bar
{
function getSelf (self $a): self
{
}
function getStatic (): static
{
}
}
$refMethodSelf = new ReflectionMethod('Foo', 'getSelf');
$refMethodStatic = new ReflectionMethod('Foo', 'getStatic');
$refParam = $refMethodSelf->getParameters()[0];
print_r(array(
'paramType' => $refParam->getType()->getName(),
'returnTypeSelf' => $refMethodSelf->getReturnType()->getName(),
'returnTypeStatic' => $refMethodStatic->getReturnType()->getName(),
));
```
Resulted in this output:
```
Array
(
[paramType] => Foo
[returnTypeSelf] => Foo
[returnTypeStatic] => static
)
```
But I expected this output instead:
```
Array
(
[paramType] => self
[returnTypeSelf] => self
[returnTypeStatic] => static
)
```
### PHP Version
```plain
PHP 8.5.3 (cli) (built: Feb 10 2026 18:25:51) (NTS)
Copyright (c) The PHP Group
Built by Shivam Mathur
Zend Engine v4.5.3, Copyright (c) Zend Technologies
with Zend OPcache v8.5.3, Copyright (c), by Zend Technologies
```
### Operating System
MacOS 15.7.4