Bug #71018 [NEW]: ReflectionProperty::setValue() behavior changed

From: Date: Thu, 03 Dec 2015 16:10:03 +0000
Subject: Bug #71018 [NEW]: ReflectionProperty::setValue() behavior changed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197570@lists.php.net to get a copy of this message
From: tony2001 Operating system: * PHP version: 7.0Git-2015-12-03 (Git) Package: Reflection related Bug Type: Bug Bug description:ReflectionProperty::setValue() behavior changed 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 bug report at https://bugs.php.net/bug.php?id=71018&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71018&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71018&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71018&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71018&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71018&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71018&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71018&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71018&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71018&r=support Expected behavior: https://bugs.php.net/fix.php?id=71018&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71018&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71018&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71018&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71018&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71018&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71018&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71018&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71018&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71018&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71018&r=mysqlcfg

« previous php.bugs (#197570) next »