From:             
Operating system: Ubuntu Linux
PHP version:      5.2.17
Package:          Class/Object related
Bug Type:         Feature/Change Request
Bug description:ArrayAccess not works properly on multi-level arrays

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 bug report at http://bugs.php.net/bug.php?id=53723&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53723&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53723&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53723&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53723&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53723&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53723&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53723&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53723&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53723&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53723&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53723&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53723&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53723&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53723&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53723&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53723&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53723&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53723&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53723&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53723&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53723&r=mysqlcfg

Reply via email to