Bug #70321 [Opn->Fbk]: Magic getter breaks reference to array property
| From: | nikic@php.net | Date: | Fri, 21 Aug 2015 17:53:21 +0000 |
| Subject: | Bug #70321 [Opn->Fbk]: Magic getter breaks reference to array property | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195411@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70321&edit=1
ID: 70321
Updated by: nikic@php.net
Reported by: hrach dot cz at gmail dot com
Summary: Magic getter breaks reference to array property
-Status: Open
+Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: win10
PHP Version: 7.0.0RC1
Block user comment: N
Private report: N
New Comment:
The behavior is the same for all PHP 7 versions: https://3v4l.org/GBpN8
Did you mean to write $bar =& $this->bar? If you don't use a by-reference assignment,
you won't be able to indirectly modify the property.
Previous Comments:
------------------------------------------------------------------------
[2015-08-21 16:42:56] hrach dot cz at gmail dot com
Description:
------------
See the testcase. Worked ok in 7.0.0-beta3
Test script:
---------------
<?php
class foo
{
private $bar;
public function __construct()
{
$this->bar = new bar();
}
public function & __get($key)
{
$bar = $this->bar;
return $bar;
}
}
class bar { public $onBaz = []; }
$foo = new foo();
$foo->bar->onBaz[] = function() {};
var_dump($foo->bar->onBaz);
Expected result:
----------------
array(1) {
[0]=>
object(Closure)#4 (0) {
}
}
Actual result:
--------------
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70321&edit=1