|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-01-12 20:55 UTC] cataphract@php.net
-Status: Open
+Status: Duplicate
[2011-01-12 20:55 UTC] cataphract@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Feb 11 08:00:01 2026 UTC |
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);