#40709 [Opn->Csd]: array_reduce behaves strange with one item stored arrays
| From: | iliaa@php.net | Date: | Sun, 04 Mar 2007 17:21:22 +0000 |
| Subject: | #40709 [Opn->Csd]: array_reduce behaves strange with one item stored arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-109868@lists.php.net to get a copy of this message | ||
ID: 40709
Updated by: iliaa@php.net
Reported By: ctulek at gmail dot com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: Windows
PHP Version: 5.2.1
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-03-03 16:20:30] ctulek at gmail dot com
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:
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40709&edit=1