php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71018 ReflectionProperty::setValue() behavior changed
Submitted: 2015-12-03 16:10 UTC Modified: 2015-12-03 16:10 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: tony2001@php.net Assigned: laruence (profile)
Status: Closed Package: Reflection related
PHP Version: 7.0Git-2015-12-03 (Git) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tony2001@php.net
New email:
PHP Version: OS:

 

 [2015-12-03 16:10 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ae3341533b68cccaccfc0d78456b72d004dfc80
Log: Fixed bug #71018 (ReflectionProperty::setValue() behavior changed)
 [2015-12-04 03:53 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2016-07-20 11:35 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ae3341533b68cccaccfc0d78456b72d004dfc80
Log: Fixed bug #71018 (ReflectionProperty::setValue() behavior changed)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC