php.net |  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
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
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
Have you experienced this issue?
Rate the importance of this bug to you:

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

https://github.com/php/php-src/commit/622d2f41d1cdb597f4fafecaaacf66e238742bd4

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: http://externals.io/thread/321

Testscript @ See https://3v4l.org/Pmu6c#v710beta3

Test script:
---------------
<?php

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) {
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-13 07:20 UTC] krakjoe@php.net
-Type: Bug +Type: Documentation Problem
 [2018-09-29 19:18 UTC] nikic@php.net
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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 23:01:25 2019 UTC