Bug #71018 [Opn->Asn]: ReflectionProperty::setValue() behavior changed

From: Date: Thu, 03 Dec 2015 16:10:13 +0000
Subject: Bug #71018 [Opn->Asn]: ReflectionProperty::setValue() behavior changed
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197571@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: tony2001@php.net Reported by: tony2001@php.net Summary: ReflectionProperty::setValue() behavior changed -Status: Open +Status: Assigned Type: Bug Package: Reflection related Operating System: * PHP Version: 7.0Git-2015-12-03 (Git) -Assigned To: +Assigned To: laruence Block user comment: N Private report: N 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

« previous php.bugs (#197571) next »