summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2007-03-04 17:21:16 +0000
committerIlia Alshanetsky <iliaa@php.net>2007-03-04 17:21:16 +0000
commit1ac71c4fe94644571aecd92bf9425e61d3cbf8bb (patch)
treea9dfc17644104e879b0befbfdfa3e7674f5f29d6
parentfa29c1a2f55b0655c6db598ec03391dc33d0cd5b (diff)
downloadphp-git-1ac71c4fe94644571aecd92bf9425e61d3cbf8bb.tar.gz
Fixed bug #40709 (array_reduce() behaves strange with one item stored
arrays).
-rw-r--r--NEWS2
-rw-r--r--ext/standard/array.c4
-rw-r--r--ext/standard/tests/array/bug40709.phpt28
3 files changed, 31 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 1cbf7898a5..2d81830e77 100644
--- 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).
diff --git a/ext/standard/array.c b/ext/standard/array.c
index be3e73c191..29b9e8dc41 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -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
index 0000000000..6ab6bbd410
--- /dev/null
+++ b/ext/standard/tests/array/bug40709.phpt
@@ -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