ID:               34982
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Closed
 Bug Type:         Arrays related
 Operating System: *
 PHP Version:      5CVS-2005-10-25 (CVS)
-Assigned To:      
+Assigned To:      dmitry
 New Comment:

Fixed in CVS HEAD, PHP_5_1 and PHP_5_0.


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

[2005-10-26 04:52:58] [EMAIL PROTECTED]

Mabey I didn't make the code clear but if you var_dump($a) right after
array_walk_recursive() all values have the value of 'changed'. The
problem is back outside of the function that called
array_walk_recursive(), the $ar variable should still retain the
original array values.

------------------------------------------------------------------------

[2005-10-25 21:57:35] [EMAIL PROTECTED]

I'd say the bug is that it *doesn't* modify the first level elements,
because it's expected when you use &$arg instead of $arg.

------------------------------------------------------------------------

[2005-10-25 21:24:38] [EMAIL PROTECTED]

Description:
------------
array_walk_recursive() modifies element values deeper than the first
level on vars outside the scope of the function call.



Reproduce code:
---------------
<?php

$ar = array(
    'element 1',
    array('element2 => subelement1')
    );

func($ar);
var_dump($ar);

function func($a) {
  array_walk_recursive($a, 'apply');
}

function apply(&$input, $key) {
  $input = 'changed';
}


Expected result:
----------------
array(2) {
  [0]=>
  string(9) "element 1"
  [1]=>
  array(1) {
    [0]=>
    string(23) "element2 => subelement1"
  }
}


Actual result:
--------------
array(2) {
  [0]=>
  string(9) "element 1"
  [1]=>
  array(1) {
    [0]=>
    string(7) "changed"
  }
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34982&edit=1

Reply via email to