php.net |  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: Closed Package: Reflection related
PHP Version: Irrelevant OS: n/a
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eric at ericstern dot com
New email:
PHP Version: OS:

 

 [2019-11-05 23:35 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-05 23:42 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: Unknown/Other Function +Package: Reflection related
 [2019-11-05 23:42 UTC] 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-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 (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-06 01:08 UTC] requinix@php.net
-Summary: ReflectionType::getName() is undocumented +Summary: class.ReflectionType page should mention ReflectionNamedType for convenience
 [2019-11-06 01:08 UTC] 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).
 [2021-07-30 13:11 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/b54e6443e29d0d77ae93d70f98b5c38e93b95b8a
Log: Fix #78785: ReflectionType page should mention subclasses
 [2021-07-30 13:11 UTC] git@php.net
-Status: Open +Status: Closed
 [2021-07-31 12:54 UTC] git@php.net
Automatic comment on behalf of mumumu
Revision: https://github.com/php/doc-ja/commit/59c5e2ddab8b0713302c7addec8ac681c765d53c
Log: Fix #78785: ReflectionType page should mention subclasses
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 24 10:03:33 2021 UTC