|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78785 class.ReflectionType page should mention ReflectionNamedType for convenience
Submitted: 2019-11-05 23:35 UTC Modified: 2019-11-06 01:08 UTC
From: eric at ericstern dot com Assigned:
Status: Open Package: Reflection related
PHP Version: Irrelevant OS: n/a
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-11-05 23:35 UTC] eric at ericstern dot com
From manual page:
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-05 23:42 UTC]
-Status: Open +Status: Feedback -Package: Unknown/Other Function +Package: Reflection related
 [2019-11-05 23:42 UTC]
I don't see anything to suggest ReflectionType::getName() exists.

Are you thinking of ReflectionNamedType::getName()?
 [2019-11-06 00:45 UTC] eric at ericstern dot com
-Status: Feedback +Status: Open
 [2019-11-06 00:45 UTC] 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 (, 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-06 01:08 UTC]
-Summary: ReflectionType::getName() is undocumented +Summary: class.ReflectionType page should mention ReflectionNamedType for convenience
 [2019-11-06 01:08 UTC]
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).
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon May 10 18:01:25 2021 UTC