Skip to content

php 8.5 ReflectionType->getName no longer returns "self" #21284

@bkdotcom

Description

@bkdotcom

Description

The following code:

https://3v4l.org/5ACeW#v8.5.3

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

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

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