Bug #72177 [NEW]: Scope issue in __destruct after ReflectionProperty::setValue()

From: Date: Mon, 09 May 2016 13:28:51 +0000
Subject: Bug #72177 [NEW]: Scope issue in __destruct after ReflectionProperty::setValue()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200955@lists.php.net to get a copy of this message
From:             lbarnaud
Operating system: 
PHP version:      7.0Git-2016-05-09 (Git)
Package:          Reflection related
Bug Type:         Bug
Bug description:Scope issue in __destruct after ReflectionProperty::setValue()

Description:
------------
When __destruct() is called, following a ReflectionProperty::setValue()
call, scopes seem to be wrong.

In the following reproducing script, the method Child::__destruct()
fails to set $this->bar to null, with the error `Cannot access
protected property Child::$bar`.

I can reproduce this in git master, but not in any version from
3v4l.org.

Test script:
---------------
<?php

class Child
{
    protected $bar;

    public function __destruct()
    {
        $this->bar = null;
    }
}

class Parnt
{
    protected $child;

    public function doSomething()
    {
        $this->child = new Child();

        $prop = new \ReflectionProperty($this, 'child');
        $prop->setAccessible(true);
        $prop->setValue($this, null);
    }
}

$p = new Parnt();
$p->doSomething();

echo "OK\n";

Expected result:
----------------
OK

Actual result:
--------------
Fatal error: Uncaught Error: Cannot access protected property
Child::$bar in /tmp/x.php:9
Stack trace:
#0 [internal function]: Child->__destruct()
#1 /tmp/x.php(23): ReflectionProperty->setValue(Object(Parnt), NULL)
#2 /tmp/x.php(28): Parnt->doSomething()
#3 {main}
  thrown in /tmp/x.php on line 9

-- 
Edit bug report at https://bugs.php.net/bug.php?id=72177&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72177&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72177&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72177&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72177&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72177&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72177&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72177&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72177&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72177&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72177&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72177&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72177&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72177&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72177&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72177&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72177&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72177&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72177&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72177&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72177&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#200955) next »