|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-31 23:51 UTC] jani@php.net
[2009-08-01 00:48 UTC] svn@php.net
[2009-08-01 00:50 UTC] jani@php.net
[2009-08-01 01:01 UTC] svn@php.net
[2009-08-01 21:10 UTC] felipe@php.net
[2009-08-02 02:49 UTC] 1000235409 at smail dot shnu dot edu dot cn
[2013-03-15 14:35 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2013-03-15 14:35 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 12:00:01 2025 UTC |
Description: ------------ When calling ReflectionClass::getStaticProperties() with a '&' operator, we can easily modify the private static fields outside the class, but only for fields declared in the parent class, not the class itself. But I don't know if PHP should make it possible to modify the inaccessible class static fields or not, since the PHP manual just contains a prototype in Reflection. Reproduce code: --------------- class Test { private static $data = 1; private static $data4 = 4; public static function test1() { echo self::$data; } } class Test2 extends Test { private static $data2 = 2; public static $data3 = 3; } $r = new ReflectionClass('Test2'); $m = & $r->getStaticProperties(); //here, with the '&' $m['data'] = 100; //$data is in the parent class. $m['data4'] = 400; //$data4 is in the parent class. $m['data2'] = 200; //no effect. $m['data3'] = 300; //no effect. Test::test1(); echo "\n"; $m = $r->getStaticProperties(); foreach ($m as $key => $val) { echo $key . '==>' . $val . "\n"; } Expected result: ---------------- 1 data2==>2 data3==>3 data==>1 data4==>4 /**OR**/ 100 data2==>200 data3==>300 data==>100 data4==>400 Actual result: -------------- 100 data2==>2 data3==>3 data==>100 data4==>400