]> granicus.if.org Git - php/commitdiff
Fixed bug #40709 (array_reduce() behaves strange with one item stored
authorIlia Alshanetsky <iliaa@php.net>
Sun, 4 Mar 2007 17:21:16 +0000 (17:21 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 4 Mar 2007 17:21:16 +0000 (17:21 +0000)
arrays).

NEWS
ext/standard/array.c
ext/standard/tests/array/bug40709.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1cbf7898a5bf5f486e272ec1e913be17b37d9875..2d81830e77a7a8800a1bc1506e6b1fdf63b073a5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,8 @@ PHP                                                                        NEWS
 - Added --ri switch to CLI which allows to check extension information. (Marcus)
 - Added tidyNode::getParent() method (John, Nuno)
 - Fixed zend_llist_remove_tail (Michael Wallner, Dmitry)
+- Fixed bug #40709 (array_reduce() behaves strange with one item stored arrays).
+  (Ilia)
 - Fixed bug #40678 (Cross compilation fails). (Tony)
 - Fixed bug #40621 (Crash when constructor called inappropriately). (Tony)
 - Fixed bug #40609 (Segfaults when using more than one SoapVar in a request).
index be3e73c191c011fb20d4a99e460ac45f885ed782..29b9e8dc410b3050e2b721adf07d1455f954c6ae 100644 (file)
@@ -4077,10 +4077,8 @@ PHP_FUNCTION(array_reduce)
        while (zend_hash_get_current_data_ex(htbl, (void **)&operand, &pos) == SUCCESS) {
                if (result) {
                        zend_fcall_info fci;
-
                        args[0] = &result;
                        args[1] = operand;
-
                        fci.size = sizeof(fci);
                        fci.function_table = EG(function_table);
                        fci.function_name = *callback;
@@ -4106,7 +4104,7 @@ PHP_FUNCTION(array_reduce)
                zend_hash_move_forward_ex(htbl, &pos);
        }
        
-       RETVAL_ZVAL(result, 0, 1);
+       RETVAL_ZVAL(result, 1, 1);
 }
 /* }}} */
 
diff --git a/ext/standard/tests/array/bug40709.phpt b/ext/standard/tests/array/bug40709.phpt
new file mode 100644 (file)
index 0000000..6ab6bbd
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Bug #40709 (array_reduce() behaves strange with one item stored arrays)
+--SKIPIF--
+--FILE--
+<?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')."\n";
+echo "result for arr2: ".array_reduce($arr2,'CommaSeperatedList')."\n";
+echo "result for arr1: ".array_reduce($arr1,'CommaSeperatedList')."\n";
+echo "result for arr2: ".array_reduce($arr2,'CommaSeperatedList')."\n";
+
+echo "Done\n";
+?>
+--EXPECT--     
+result for arr1: 1,2,3
+result for arr2: 1
+result for arr1: 1,2,3
+result for arr2: 1
+Done