#42654 [Asn->Csd]: recursiveIteratorIterator modify only part of leaves
| From: | helly@php.net | Date: | Thu, 18 Oct 2007 05:52:37 +0000 |
| Subject: | #42654 [Asn->Csd]: recursiveIteratorIterator modify only part of leaves | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118650@lists.php.net to get a copy of this message | ||
ID: 42654
Updated by: helly@php.net
Reported By: ltaupiac at lfdj dot com
-Status: Assigned
+Status: Closed
Bug Type: SPL related
Operating System: windows
PHP Version: 5CVS-2007-09-13 (snap)
Assigned To: helly
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-09-13 09:51:36] jani@php.net
Assigned to the SPL maintainer.
------------------------------------------------------------------------
[2007-09-13 09:48:31] ltaupiac at lfdj dot com
Description:
------------
when recursively iterate over recursive array to alter leaves, only
first leaves are altered.
Reproduce code:
---------------
$data = array ('key1' => 'val1', array('key2' =>
'val2'), 'key3' =>
'val3');
$iterator = new RecursiveIteratorIterator(new
RecursiveArrayIterator($data));
foreach($iterator as $foo) {
$key = $iterator->key();
switch($key) {
case 'key1': // first level
case 'key2': // recursive level
echo "update $key<br>";
$iterator->offsetSet($key, 'alter');
}
}
$copy = $iterator->getArrayCopy();
var_dump($copy);
Expected result:
----------------
update key1
update key2
array(3) {
["key1"]=>
string(5) "alter"
[0]=>
array(1) {
["key2"]=>
string(4) "alter"
}
["key3"]=>
string(4) "val3"
}
Actual result:
--------------
update key1
update key2
array(3) {
["key1"]=>
string(5) "alter"
[0]=>
array(1) {
["key2"]=>
string(4) "val2"
}
["key3"]=>
string(4) "val3"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42654&edit=1