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
 [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

Pull Requests

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 Nov 21 08:01:29 2024 UTC