ID: 40823 Updated by: [EMAIL PROTECTED] Reported By: php at michaelho dot com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Mac OS X 10.4.9 PHP Version: 5.2.1 New Comment:
Please read what Derick said in bug #40625. It DID NOT work before and the only difference is the notice. To make it work you need to return __get() result by reference: <?php class Foo { private $array = array(1, 2, 3); public function &__get($name) { //<------- & return (array) $this->array; } } $a = new foo(); $a->overloaded[] = 4; foreach ($a->overloaded as $int) print $int . "<br/>"; ?> And that's really easy to explain - you can't change the result of the __get() method and expect it to affect the object members. Previous Comments: ------------------------------------------------------------------------ [2007-03-15 17:17:00] php at michaelho dot com Description: ------------ This was mistakenly reported as "bogus" in http://bugs.php.net/bug.php?id=40625 Overloaded array access was implemented then broken, then fixed again in PHP 5.2.0: http://bugs.php.net/39449 However, with PHP 5.2.1, it was broken once again. The following code sample works perfectly in 5.2.0, but is broken in 5.2.1 Reproduce code: --------------- <?php class Foo { private $array = array(1, 2, 3); public function __get($name) { return (array) $this->array; } } $a = new foo(); $a->overloaded[] = 4; foreach ($a->overloaded as $int) print $int . "<br/>"; ?> Expected result: ---------------- 1 2 3 4 Actual result: -------------- Notice: Indirect modification of overloaded property Foo::$overloaded has no effect in /deb/blah/wwwroot/test.php on line 10 1 2 3 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40823&edit=1