|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73459 ReflectionFunction:getReturnType returns ReflectionNamedType object.
Submitted: 2016-11-04 15:19 UTC Modified: 2018-09-29 19:18 UTC
Avg. Score:4.0 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: arjen at parse dot nl Assigned:
Status: Open Package: Reflection related
PHP Version: 7.1.0RC5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: arjen at parse dot nl
New email:
PHP Version: OS:


 [2016-11-04 15:19 UTC] arjen at parse dot nl
In 7.1.0beta3 ReflectionNamedType was introduced, documentation not updated.
The original ReflectionType is not instantiated anymore.

I don't think this class change is intentional, this would be an even bigger BC break than the discussed ReflectionType::__toString change discussed on internals:

Testscript @ See

Test script:

class B
    public function test(): B

function getB(): B

$rc = new ReflectionMethod('B', 'test');
var_dump((string)$rc->getReturnType(), $rc->getReturnType());

$rc = new ReflectionFunction('getB');
var_dump((string)$rc->getReturnType(), $rc->getReturnType());

Expected result:
string(1) "B"
object(ReflectionType)#2 (0) {
string(1) "B"
object(ReflectionType)#1 (0) {

Actual result:
string(2) "\B"
object(ReflectionNamedType)#2 (0) {
string(2) "\B"
object(ReflectionNamedType)#1 (0) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-13 07:20 UTC]
-Type: Bug +Type: Documentation Problem
 [2018-09-29 19:18 UTC]
The documentation is correct -- we only guarantee that a ReflectionType is returned. ReflectionNamedType is a specific ReflectionType. In the future it might also return something like ReflectionUnionType (another specific ReflectionType).

Return types do not specify that *exactly* that class will be returned, only that it's that class or a subtype. Right now it will always be ReflectionNamedType, but this is not guaranteed, by design.
 [2019-11-09 15:34 UTC] chef at web-cooking dot net
In it is explained in examples section. (with a small mistake : ReflectionNamedType() instead of ReflectionNamedType::getName())

It is not on though.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 06:01:28 2024 UTC