php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77325 ReflectionClassConstant::$class returns wrong class when extending
Submitted: 2018-12-20 13:43 UTC Modified: 2018-12-20 23:37 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: me at vasekpurchart dot cz Assigned:
Status: Closed Package: Reflection related
PHP Version: 7.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 37 = ?
Subscribe to this entry?

 
 [2018-12-20 13:43 UTC] me at vasekpurchart dot cz
Description:
------------
The property ReflectionClassConstant::$class is documented as:

http://php.net/manual/en/class.reflectionclassconstant.php#reflectionclassconstant.props

> Name of the class where the class constant is defined.

When using a hierarchy of classes and having constants defined on multiple levels this does return the child class where the constant is not defined.

Although using ReflectionClassConstant::getDeclaringClass() returns the correct one. In fact these two should point to the same class.

Test script:
---------------
https://3v4l.org/f0WZf

Expected result:
----------------
ReflectionClassConstant::class should return the class where the constant is really declared as stated in the docs.

This would also mean, that $constant->class === $constant->getDeclaringClass()->getName() is true.

This would also bring the constants in line with methods and properties, where this works correctly (as can be seen for example here https://3v4l.org/rqUF2).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-20 23:37 UTC] cmb@php.net
-PHP Version: 7.3.0 +PHP Version: 7.2
 [2020-02-28 16:21 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0d06a63ee311270a25bc0147271215c3ad90eba0
Log: Fixed bug #77325
 [2020-02-28 16:21 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 04:01:38 2024 UTC