|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-12-03 16:10 UTC] tony2001@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: laruence
[2015-12-04 03:53 UTC] laruence@php.net
[2015-12-04 03:53 UTC] laruence@php.net
-Status: Assigned
+Status: Closed
[2016-07-20 11:35 UTC] davey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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"