Bug #69456 [NEW]: can't set protected / private static methods on ReflectionClass object

From: Date: Wed, 15 Apr 2015 05:51:14 +0000
Subject: Bug #69456 [NEW]: can't set protected / private static methods on ReflectionClass object
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192070@lists.php.net to get a copy of this message
From: cameron at datashovel dot com Operating system: AWS Linux PHP version: 5.5.23 Package: Reflection related Bug Type: Bug Bug description:can't set protected / private static methods on ReflectionClass object Description: ------------ I can't seem to set new values on static properties using either setValue or setStaticPropertyValue using ReflectionClass Test script: --------------- <?php $array = array( 'blah1' => 1, 'blah2' => 2, 'blah3' => 3 ); class Blah { public static $blah1 = 4; protected static $blah2 = 5; private static $blah3 = 6; } $rc = new ReflectionClass('Blah'); // brand new ReflectionClass var_dump($rc); $static = $rc->getProperties(ReflectionProperty::IS_STATIC); $obj = $rc->newInstanceWithoutConstructor(); foreach($static as $prop){ if(!empty($arr[$prop->getName()])){ $prop->setAccessible(true); $prop->setValue($obj, $arr[$prop->getName()]); $rc->setStaticPropertyValue($prop->getName(), self::cast($arr[$prop->getName()])); } } $obj2 = $rc->newInstanceWithoutConstructor(); // instantiate class after ReflectionClass has set all property values var_dump($obj2); var_dump($obj2::$blah1); // class instantiated before ReflectionClass captured ReflectionClass values // but after we have called "setValue" var_dump($obj); var_dump($obj::$blah1); Expected result: ---------------- either by calling setValue OR by instantiating a new instance AFTER setting the Static properties on the ReflectionClass object I should be able to set static values. Obviously public static is less of an issue because since I could just go in afterward and set the value on the instance. But protected and private pose a problem because unless I create special setters / getters I will be unable to set custom values on these properties through reflection. Actual result: -------------- object(ReflectionClass)#1 (1) { ["name"]=> string(4) "Blah" } object(Blah)#6 (0) { } int(4) object(Blah)#5 (0) { } int(4) -- Edit bug report at https://bugs.php.net/bug.php?id=69456&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69456&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69456&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69456&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69456&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69456&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69456&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69456&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69456&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69456&r=support Expected behavior: https://bugs.php.net/fix.php?id=69456&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69456&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69456&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69456&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69456&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69456&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69456&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69456&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69456&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69456&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69456&r=mysqlcfg

« previous php.bugs (#192070) next »