|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80564 ReflectionProperty::__toString() renders current value, not default value
Submitted: 2020-12-30 04:43 UTC Modified: 2021-07-23 07:46 UTC
From: david at grudl dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 8.0.1RC1 OS:
Private report: No CVE-ID: None
 [2020-12-30 04:43 UTC] david at grudl dot com
ReflectionProperty::__toString() convert also value of property to string and it may fail, see

Test script:

class A
	public static $x;

A::$x = new stdClass;

$rp = new ReflectionProperty('A', 'x');
echo $rp;

Expected result:
Property [ public static $x ]

Actual result:
Fatal error: Uncaught Error: Object of class stdClass could not be converted to string


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-30 06:30 UTC]
-Summary: ReflectionProperty::__toString() converts property value to string +Summary: ReflectionProperty::__toString() renders current value, not default value -Status: Open +Status: Verified
 [2020-12-30 06:30 UTC]
Fails during

zval *default_value = property_get_default(prop);
if (!Z_ISUNDEF_P(default_value)) {
    smart_str_appends(str, " = ");
    if (format_default_value(str, default_value, prop->ce) == FAILURE) {

Apparently it's trying to get a default value but is actually coming up with the current value.
 [2021-07-23 07:46 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 21:01:33 2024 UTC