Doc #78785 [Opn->Csd]: class.ReflectionType page should mention ReflectionNamedType for convenience
| From: | git@php.net | Date: | Fri, 30 Jul 2021 13:11:15 +0000 |
| Subject: | Doc #78785 [Opn->Csd]: class.ReflectionType page should mention ReflectionNamedType for convenience | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-19009@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78785&edit=1
ID: 78785
Updated by: git@php.net
Reported by: eric at ericstern dot com
Summary: class.ReflectionType page should mention
ReflectionNamedType for convenience
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Reflection related
Operating System: n/a
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/b54e6443e29d0d77ae93d70f98b5c38e93b95b8a
Log: Fix #78785: ReflectionType page should mention subclasses
Previous Comments:
------------------------------------------------------------------------
[2019-11-06 01:08:36] requinix@php.net
ReflectionType is meant as the base class it is, which means the proper procedure for dealing with
values is to test for possible subtypes and react accordingly. Currently ReflectionNamedType is the
only subtype, and last I knew it is always used and never ReflectionType itself, so if you were lazy
you could skip the hassle and just assume it, but the hierarchy exists so that it can be expanded
upon in the future (thinking about unioned types) without having to retcon anything
(coughexceptions).
------------------------------------------------------------------------
[2019-11-06 00:45:25] eric at ericstern dot com
Actually, that does seem like the case. I followed the docs from
ReflectionFunctionAbstract->getReturnType() and wasn't aware that the subclass existed. When
actually running the code, I simply guessed at a couple of names that might work based on the other
Reflection APIs, and getName() happened to work.
If that's the case, it would be beneficial to expand the docs around that area - as it stands
now, the examples are relying on the deprecated functionality
(https://www.php.net/manual/en/reflectionfunctionabstract.getreturntype.php), and it's not
clear when (or even if) the base ReflectionType would be returned and not ReflectionNamedType. At
best, this means having to add additional instanceof checks to code working with these APIs.
------------------------------------------------------------------------
[2019-11-05 23:42:48] requinix@php.net
I don't see anything to suggest ReflectionType::getName() exists.
Are you thinking of ReflectionNamedType::getName()?
https://www.php.net/manual/en/reflectionnamedtype.getname.php
------------------------------------------------------------------------
[2019-11-05 23:35:13] eric at ericstern dot com
Description:
------------
---
From manual page: https://php.net/class.reflectiontype
---
As of 7.1.0, ReflectionType::__toString() has been deprecated. There appears to be a getName()
method which functions as a replacement, but it is both completely undocumented and not even visible
by use of the reflection APIs.
The getName() method either should be documented (another bug suggests it was intentionally
removed), or a suitable equivalent should be exposed and documented. As it is, the ReflectionType
class is completely useless without having some way to access the type it represents.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78785&edit=1