Edit report at http://bugs.php.net/bug.php?id=53723&edit=1
ID: 53723 Updated by: [email protected] Reported by: zsolt94 at gmail dot com Summary: ArrayAccess not works properly on multi-level arrays -Status: Open +Status: Duplicate Type: Feature/Change Request Package: Class/Object related Operating System: Ubuntu Linux PHP Version: 5.2.17 Block user comment: N Private report: N New Comment: Duplicate/fixed in PHP 5.3.4, where you can make offsetGet return by ref. Previous Comments: ------------------------------------------------------------------------ [2011-01-12 14:04:23] zsolt94 at gmail dot com Description: ------------ If I use an Object, with an ArrayAccess interface, I can't modify element arrays the same way like 2-dimensional arrays Test script: --------------- <?php // Just a simple class, for testing. class ArrayTest implements ArrayAccess { private $array; public function offsetGet($offset) { return $this->array[$offset]; } public function offsetSet($offset,$value) { $this->array[$offset] = $value; } public function offsetUnset($offset) { unset($this->array[$offset]); } public function offsetExists($offset) { return isset($this->array[$offset]); } } $a = new ArrayTest(); $b = new ArrayTest(); $a['numbers'] = array('one'=>1); var_dump($a['numbers']); $b['numbers']['one'] = 1; var_dump($b['numbers']); ?> Expected result: ---------------- I want to get: array ( 'one' => 1, ) array ( 'one' => 1, ) But I got instead: array ( 'one' => 1, ) Notice: Indirect modification of overloaded element of ArrayTest has no effect in /home/zsolt94/www/oopy/arraytest.php on line 30 null I think that: $a['foo']['bar'] = $anything; Should do the same effect as that: $foo = $a['foo']; $foo['bar'] = $anything; $a['foo'] = $foo; unset($foo); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53723&edit=1
