Doc #73459 [Opn]: ReflectionFunction:getReturnType returns ReflectionNamedType object.

From: Date: Sat, 29 Sep 2018 19:18:11 +0000
Subject: Doc #73459 [Opn]: ReflectionFunction:getReturnType returns ReflectionNamedType object.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16023@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 Updated by: nikic@php.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: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#16023) next »