Doc #73459 [Com]: ReflectionFunction:getReturnType returns ReflectionNamedType object.
| From: | chef at web-cooking dot net | Date: | Sat, 09 Nov 2019 15:34:34 +0000 |
| Subject: | Doc #73459 [Com]: ReflectionFunction:getReturnType returns ReflectionNamedType object. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17055@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73459&edit=1
ID: 73459
Comment by: chef at web-cooking dot net
Reported by: arjen at parse dot nl
Summary: ReflectionFunction:getReturnType returns
ReflectionNamedType object.
Status: Open
Type: Documentation Problem
Package: Reflection related
Operating System: Linux
PHP Version: 7.1.0RC5
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-09-29 19:18:11] 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.
------------------------------------------------------------------------
[2016-11-04 15:19:28] 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) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73459&edit=1