php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40709 array_reduce behaves strange with one item stored arrays
Submitted: 2007-03-03 16:20 UTC Modified: 2007-03-04 17:21 UTC
From: ctulek at gmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.2.1 OS: Windows
Private report: No CVE-ID:
 [2007-03-03 16:20 UTC] 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: 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-04 17:21 UTC] iliaa@php.net
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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 08:02:55 2014 UTC