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:3
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: arjen at parse dot nl
New email:
PHP Version: OS:

 

 [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

Pull Requests

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.
 [2019-11-09 15:34 UTC] chef at web-cooking dot net
In https://www.php.net/reflectionparameter.gettype it is explained in examples section. (with a small mistake : ReflectionNamedType() instead of ReflectionNamedType::getName())

It is not on https://www.php.net/reflectionfunctionabstract.getreturntype though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 07:01:27 2024 UTC