CINXE.COM
PHP :: Bug #77325 :: ReflectionClassConstant::$class returns wrong class when extending
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <link rel='alternate' type='application/rss+xml' title='Reflection related Bug #77325 - RDF' href='rss/bug.php?id=77325'> <link rel='alternate' type='application/rss+xml' title='Reflection related Bug #77325 - RSS 2.0' href='rss/bug.php?id=77325&format=rss2'> <base href="https://bugs.php.net/"> <title>PHP :: Bug #77325 :: ReflectionClassConstant::$class returns wrong class when extending</title> <link rel="shortcut icon" href="https://bugs.php.net/images/favicon.ico"> <link rel="stylesheet" href="https://bugs.php.net/css/style.css"> </head> <body> <table id="top" class="head" cellspacing="0" cellpadding="0"> <tr> <td class="head-logo"> <a href="/"><img src="images/logo.png" alt="Bugs" vspace="2" hspace="2"></a> </td> <td class="head-menu"> <a href="https://php.net/">php.net</a> | <a href="https://php.net/support.php">support</a> | <a href="https://php.net/docs.php">documentation</a> | <a href="report.php">report a bug</a> | <a href="search.php">advanced search</a> | <a href="search-howto.php">search howto</a> | <a href="stats.php">statistics</a> | <a href="random">random bug</a> | <a href="login.php">login</a> </td> </tr> <tr> <td class="head-search" colspan="2"> <form method="get" action="search.php"> <p class="head-search"> <input type="hidden" name="cmd" value="display"> <small>go to bug id or search bugs for</small> <input class="small" type="text" name="search_for" value="" size="30"> <input type="image" src="images/small_submit_white.gif" alt="search" style="vertical-align: middle;"> </p> </form> </td> </tr> </table> <table class="middle" cellspacing="0" cellpadding="0"> <tr> <td class="content"> <div id="bugheader"> <table id="details"> <tr id="title"> <th class="details" id="number"><a href="bug.php?id=77325">Bug</a> #77325</th> <td id="summary" colspan="5">ReflectionClassConstant::$class returns wrong class when extending</td> </tr> <tr id="submission"> <th class="details">Submitted:</th> <td style="white-space: nowrap;">2018-12-20 13:43 UTC</td> <th class="details">Modified:</th> <td style="white-space: nowrap;">2018-12-20 23:37 UTC</td> <td rowspan="6"> <table id="votes"> <tr><th class="details">Votes:</th><td>1</td></tr> <tr><th class="details">Avg. Score:</th><td>3.0 ± 0.0</td></tr> <tr><th class="details">Reproduced:</th><td>0 of 0 (0.0%)</td></tr> </table> </td> </tr> <tr id="submitter"> <th class="details">From:</th> <td>me at vasekpurchart dot cz</td> <th class="details">Assigned:</th> <td></td> </tr> <tr id="categorization"> <th class="details">Status:</th> <td>Closed</td> <th class="details">Package:</th> <td><a href="search.php?cmd=display&package_name[]=Reflection+related">Reflection related</a></td> </tr> <tr id="situation"> <th class="details">PHP Version:</th> <td>7.2</td> <th class="details">OS:</th> <td></td> </tr> <tr id="private"> <th class="details">Private report:</th> <td>No</td> <th class="details">CVE-ID:</th> <td><em>None</em></td> </tr> </table> </div> <div class="controls"> <span id='control_0' class='control active'>View</span> <span id='control_1' class='control'><a href='bug.php?id=77325&edit=1'>Developer</a></span> <span id='control_2' class='control'><a href='bug.php?id=77325&edit=2'>Edit</a></span> </div> <div class="clear"></div> <div class='comment type_comment' ><a name="1545313383"> </a><strong>[2018-12-20 13:43 UTC] me at vasekpurchart dot cz</strong> <pre class='note'>Description: ------------ The property ReflectionClassConstant::$class is documented as: <a href="http://php.net/manual/en/class.reflectionclassconstant.php#reflectionclassconstant.props" rel="nofollow">http://php.net/manual/en/class.reflectionclassconstant.php#reflectionclassconstant.props</a> > 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: --------------- <a href="https://3v4l.org/f0WZf" rel="nofollow">https://3v4l.org/f0WZf</a> 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 <a href="https://3v4l.org/rqUF2" rel="nofollow">https://3v4l.org/rqUF2</a>). </pre> </div><h2>Patches</h2> <h2>Pull Requests</h2> <h2 style="border-bottom:2px solid #666;margin-bottom:0;padding:5px 0;">History</h2><div id='comment_filter' class='controls comments'><span id='type_all' class='control active' onclick='do_comment(this);'>All</span><span id='type_comment' class='control ' onclick='do_comment(this);'>Comments</span><span id='type_log' class='control ' onclick='do_comment(this);'>Changes</span><span id='type_svn' class='control ' onclick='do_comment(this);'>Git/SVN commits</span><span id='type_related' class='control ' onclick='do_comment(this);'>Related reports</span> </div> <div id='comments_view' style='clear:both;'> <div class='comment type_log' ><a name="1545349077"> </a><strong>[2018-12-20 23:37 UTC] <a href="//people.php.net/cmb">cmb@php.net</a></strong> <div class='log_note'><div class="changeset"> <span class="removed">-PHP Version: 7.3.0</span> <span class="added">+PHP Version: 7.2</span> </div></div></div><div class='comment type_svn' ><a name="1582906899"> </a><strong>[2020-02-28 16:21 UTC] <a href="//people.php.net/nikic">nikic@php.net</a></strong> <pre class='note'>Automatic comment on behalf of nikita.ppv@gmail.com Revision: <a href="http://git.php.net/?p=php-src.git;a=commit;h=0d06a63ee311270a25bc0147271215c3ad90eba0" rel="nofollow">http://git.php.net/?p=php-src.git;a=commit;h=0d06a63ee311270a25bc0147271215c3ad90eba0</a> Log: Fixed <a href='bug.php?id=77325'>bug #77325</a> </pre> </div><div class='comment type_log' ><a name="1582906899"> </a><strong>[2020-02-28 16:21 UTC] <a href="//people.php.net/nikic">nikic@php.net</a></strong> <div class='log_note'><div class="changeset"> <span class="removed">-Status: Open</span> <span class="added">+Status: Closed</span> </div></div></div></div> </td> </tr> </table> <script src='js/util.js'></script> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script> <script src="js/jquery.cookie.js"></script> <script> function do_comment(nd) { $('#comment_filter > .control.active').removeClass("active"); $(nd).addClass("active"); $.cookie('history_tab', nd.id, { expires: 365 }); if (nd.id == 'type_all') { $('#comments_view > .comment:hidden').show('slow'); } else { $('#comments_view > .comment').each(function(i) { if ($(this).hasClass(nd.id)) { $(this).show('slow'); } else { $(this).hide('slow'); } }); } return false; } </script> <table class="foot" cellspacing="0" cellpadding="0"> <tr> <td class="foot-bar" colspan="2"> </td> </tr> <tr> <td class="foot-copy"> <small> <a href="https://php.net/"><img src="images/logo-small.gif" align="left" valign="middle" hspace="3" alt="PHP"></a> <a href="https://php.net/copyright.php">Copyright © 2001-2024 The PHP Group</a><br> All rights reserved. </small> </td> <td class="foot-source"> <small>Last updated: Thu Dec 12 22:01:39 2024 UTC</small> </td> </tr> </table> </body> </html>