Req #53723 [NEW]: ArrayAccess not works properly on multi-level arrays

From: Date: Wed, 12 Jan 2011 13:04:23 +0000
Subject: Req #53723 [NEW]: ArrayAccess not works properly on multi-level arrays
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-157848@lists.php.net to get a copy of this message
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



Thread (2 messages)

« previous php.bugs (#157848) next »