Bug #80564 [Ver->Csd]: ReflectionProperty::__toString() renders current value, not default value
Edit report at https://bugs.php.net/bug.php?id=80564&edit=1
ID: 80564
Updated by: nikic@php.net
Reported by: david at grudl dot com
Summary: ReflectionProperty::__toString() renders current
value, not default value
-Status: Verified
+Status: Closed
Type: Bug
Package: Reflection related
PHP Version: 8.0.1RC1
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Has been fixed by https://github.com/php/php-src/commit/3eb97a456648c739533d92c81102cb919eab01c9.
Test added in https://github.com/php/php-src/commit/5ac55af5e5a2282a15cde6aa477291d1d8f46564.
Previous Comments:
------------------------------------------------------------------------
[2020-12-30 06:30:07] requinix@php.net
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) {
return;
}
}
Apparently it's trying to get a default value but is actually coming up with the current value.
https://3v4l.org/g4OLG
------------------------------------------------------------------------
[2020-12-30 04:43:39] david at grudl dot com
Description:
------------
ReflectionProperty::__toString() convert also value of property to string and it may fail, see https://3v4l.org/rfoGl
Test script:
---------------
<?php
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80564&edit=1
Thread (4 messages)