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: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ctulek at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 22 13:01:32 2025 UTC