ID:               42654
 Updated by:       [EMAIL PROTECTED]
 Reported By:      ltaupiac at lfdj dot com
-Status:           Open
+Status:           Assigned
 Bug Type:         SPL related
 Operating System: windows
 PHP Version:      5CVS-2007-09-13 (snap)
-Assigned To:      
+Assigned To:      helly
 New Comment:

Assigned to the SPL maintainer.


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to