From:             ltaupiac at lfdj dot com
Operating system: windows/solaris
PHP version:      5.2.4
PHP Bug Type:     Arrays related
Bug description:  array_walk_recursive() leaves references

Description:
------------
I have to reopen this bug http://bugs.php.net/bug.php?id=42655 because it
was incorrectly closed and tony2001 doesn't seem to receive email.

Here Copy/paste email i send him.

This is not the same bug.

In #34982, an array is modified outside the function func() that call
array_walk_recursive. This bug doesn't exist anymore in 5.2.4

The bug i report is when calling array_walk_recursive on an array
(callback function doesn't even have reference & for array input and does
nothing).
Original array shouldn't be modified, but if you var_dump it, you can see
reference on subarray

[0]=> &array(1)

instead of

[0]=>  array(1)

The array shouldn't have been modified but array_walk_recursive leaves
references.
This can cause trouble, eg you cant duplicate the original array anymore.
Look at following example

$data = array ('key1' => 'val1', array('key2' => 'val2'));

function foo($item, $key) {}; // dumb callback function
var_dump($data);
array_walk_recursive($data, 'foo');
$data2 = $data;      // Duplicate array
$data2[0] = 'altered'; // Alter copy
var_dump($data);
var_dump($data2);

array(2) {
  ["key1"]=> string(4) "val1"
  [0]=> &string(5) "bingo"
}
array(2) {
  ["key1"]=> string(4) "val1"
  [0]=> &string(5) "bingo"
}

both $data and $data2 are altered;


Reproduce code:
---------------
$data = array ('key1' => 'val1', array('key2' => 'val2'));

function dumb($i, $k){}

var_dump($data);
array_walk_recursive($data,'foo');

// Double check the [0]=>&array(1) in actual  result
var_dump($data);

Expected result:
----------------
Expected result:
----------------
array(2) {
  ["key1"]=> string(4) "val1"
  [0]=> array(1) {
    ["key2"]=> string(4) "val2"
  }
}
array(2) {
  ["key1"]=> string(4) "val1"
  [0]=> array(1) {
    ["key2"]=> string(4) "val2"
  }
}

Actual result:
--------------
Actual result:
--------------
array(2) {
  ["key1"]=> string(4) "val1"
  [0]=> array(1) {
    ["key2"]=> string(4) "val2"
  }
}
array(2) {
  ["key1"]=> string(4) "val1"
  [0]=> &array(1) {
    ["key2"]=> string(4) "val2"
  }
}

-- 
Edit bug report at http://bugs.php.net/?id=42850&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42850&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42850&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42850&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42850&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42850&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42850&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42850&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42850&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42850&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42850&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42850&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42850&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42850&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42850&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42850&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42850&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42850&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42850&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42850&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42850&r=mysqlcfg

Reply via email to