Bug #71018 [Asn->Csd]: ReflectionProperty::setValue() behavior changed
| From: | laruence@php.net | Date: | Fri, 04 Dec 2015 03:53:58 +0000 |
| Subject: | Bug #71018 [Asn->Csd]: ReflectionProperty::setValue() behavior changed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197579@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71018&edit=1
ID: 71018
Updated by: laruence@php.net
Reported by: tony2001@php.net
Summary: ReflectionProperty::setValue() behavior changed
-Status: Assigned
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: *
PHP Version: 7.0Git-2015-12-03 (Git)
Assigned To: laruence
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ae3341533b68cccaccfc0d78456b72d004dfc80
Log: Fixed bug #71018 (ReflectionProperty::setValue() behavior changed)
Previous Comments:
------------------------------------------------------------------------
[2015-12-03 16:10:01] tony2001@php.net
Description:
------------
In PHP5 using ReflectionProperty and changing static attribute of child class directly results in
the same behavior: the property is changed for both the parent and the child classes. (I don't
think it's actually correct, but at least it's consistent).
In PHP7 this only works when changing the property directly, but ReflectionProperty::setValue() only
changes the attribute value for the child class.
See #1 and #2 in the attached code.
Test script:
---------------
<?php
class T1 {
public static $data;
public static function getDataBySelf()
{
return self::$data;
}
public static function getDataByStatic()
{
return static::$data;
}
}
class T2 extends T1 {}
$Prop1 = new ReflectionProperty(T1::class, 'data');
$Prop2 = new ReflectionProperty(T2::class, 'data');
// #1
// prints: hello, hello in PHP5, but world, hello in PHP7 - not OK
$Prop1->setValue(\T1::class, "world");
$Prop2->setValue(\T2::class, 'hello');
// #2
// prints: hello, hello in both PHP5 and PHP7 - OK
//T1::$data = "world";
//T2::$data = 'hello';
var_dump("T2::self = " . T2::getDataBySelf());
var_dump("T2::static = " . T2::getDataByStatic());
Expected result:
----------------
string(16) "T2::self = hello"
string(18) "T2::static = hello"
Actual result:
--------------
string(16) "T2::self = world"
string(18) "T2::static = hello"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71018&edit=1