|  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
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
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.
Bug Type:
From: me at vasekpurchart dot cz
New email:
PHP Version: OS:


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

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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-20 23:37 UTC]
-PHP Version: 7.3.0 +PHP Version: 7.2
 [2020-02-28 16:21 UTC]
Automatic comment on behalf of
Log: Fixed bug #77325
 [2020-02-28 16:21 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 17:01:24 2023 UTC