ID: 40216 Updated by: [EMAIL PROTECTED] Reported By: scott dot pascoe at gmail dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Windows XP PHP Version: 5.2.1RC3 New Comment:
<?php class ParameterHolder { protected $parameters = array(); public function &get($name) { return $this->parameters['test'][$name]; } public function setByRef($name, & $value) { if (!isset($this->parameters['test'])) $this->parameters['test'] = array(); $this->parameters['test'][$name] =& $value; } } class Bug39449 { protected $varHolder = null; public function __construct() { $this->varHolder = new ParameterHolder(); } public function getVarHolder() { return $this->varHolder; } public function __set($key, $value) { return $this->varHolder->setByRef($key, $value); } public function &__get($key) { /* NB */ return $this->varHolder->get($key); } } $b = new Bug39449(); $b->foo = Array(); $b->foo[0] = 'bar'; foreach ($b->foo as $k => $v) { echo "$k => $v\n"; } ?> Previous Comments: ------------------------------------------------------------------------ [2007-01-24 13:24:36] scott dot pascoe at gmail dot com Sorry, I hacked too much out of it to make it be very small. Replacing the '$ns' references with "'test'" will make it work. Scott ------------------------------------------------------------------------ [2007-01-24 09:27:25] [EMAIL PROTECTED] This code does not work at all: Parse error: syntax error, unexpected '&' in /tmp/4.php on line 8 Notice: Undefined variable: ns in /tmp/4.php on line 11 ------------------------------------------------------------------------ [2007-01-24 05:39:21] scott dot pascoe at gmail dot com Description: ------------ The reproduce code is in a test format. In php 5.1.4, it outputs the expected output, it does not in 5.2.0, or does it in the 5.2.1 snapshot from today. It was reported to be fixed on 2007-01-10, but isn't yet. The symfony framework depends upon this capability. Reproduce code: --------------- --TEST-- Bug #39449 (Behavior changed from php 5.1.4 to 5.2.0) --FILE-- <?php // hacked for this test $ns = 'test'; class ParameterHolder { protected $parameters = array(); public function & get($name) { return & $this->parameters[$ns][$name]; } public function setByRef($name, & $value) { if (!isset($this->parameters[$ns])) $this->parameters[$ns] = array(); $this->parameters[$ns][$name] =& $value; } } class Bug39449 { protected $varHolder = null; public function __construct() { $this->varHolder = new ParameterHolder(); } public function getVarHolder() { return $this->varHolder; } public function __set($key, $value) { return $this->varHolder->setByRef($key, $value); } public function __get($key) { return $this->varHolder->get($key); } } $b = new Bug39449(); $b->foo = Array(); $b->foo[0] = 'bar'; foreach ($b->foo as $k => $v) { echo "$k => $v\n"; } ?> --EXPECT-- 0 => bar Expected result: ---------------- 0 => bar Actual result: -------------- [nothing] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40216&edit=1