Description:
------------
array_reduce seems to modify, after one call, arrays which have only one item. This can be observed with many different ways. One example code is given.
Reproduce code:
---------------
<?php
function CommaSeperatedList($a, $b) {
if($a == null)
return $b;
else
return $a.','.$b;
}
$arr1 = array(1,2,3);
$arr2 = array(1);
echo "result for arr1: ".array_reduce($arr1,'CommaSeperatedList')."<br>";
echo "result for arr2: ".array_reduce($arr2,'CommaSeperatedList')."<br>";
echo "result for arr1: ".array_reduce($arr1,'CommaSeperatedList')."<br>";
echo "result for arr2: ".array_reduce($arr2,'CommaSeperatedList')."<br>";
?>
Expected result:
----------------
result for arr1: 1,2,3
result for arr2: 1
result for arr1: 1,2,3
result for arr2: 1
Actual result:
--------------
result for arr1: 1,2,3
result for arr2: 1
result for arr1: 1,2,3
result for arr2:

Patches

Pull Requests

History

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.