Bug #70321 [Com]: Magic getter breaks reference to array property

From: Date: Fri, 21 Aug 2015 18:42:07 +0000
Subject: Bug #70321 [Com]: Magic getter breaks reference to array property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195413@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 Comment by: bugs dot php dot net at majkl578 dot cz Reported by: hrach dot cz at gmail dot com Summary: Magic getter breaks reference to array property 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: I did some git-bisecting (because we originally thought it was caused by a fix for #70262) and it lead me to 38151a38ec31af33e10513cc39e7cac8f819f120, a commit from 4 Mar 2014. Anything newer appears to return an empty array... Tried with ./configure --disable-all --enable-cli on Debian x86_64. Previous Comments: ------------------------------------------------------------------------ [2015-08-21 18:24:25] hrach dot cz at gmail dot com No, on Windows the bahavior has changed: /d/storage $ php --version PHP 7.0.0beta3 (cli) (built: Aug 5 2015 12:17:06) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies /d/storage $ php test.php array(1) { [0]=> object(Closure)#3 (0) { } } /d/storage $ php --version PHP 7.0.0RC1 (cli) (built: Aug 20 2015 12:42:50) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies /d/storage $ php test.php array(0) { } On Linux probably too, since travis was ok! - ok: https://travis-ci.org/nextras/orm/jobs/72314843 - broken: https://travis-ci.org/nextras/orm/jobs/76666269 I do not meant that proposed change. Since I'm returning object by magic getter, it's has no meaning to put the reference there. The reference would be important for that magic property, not the holding object itself, wouldn't be? ------------------------------------------------------------------------ [2015-08-21 17:53:21] nikic@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#195413) next »