]> granicus.if.org Git - php/commitdiff
This commit was manufactured by cvs2svn to create branch 'PHP_4_3'.
authorSVN Migration <svn@php.net>
Sat, 9 Aug 2003 16:44:34 +0000 (16:44 +0000)
committerSVN Migration <svn@php.net>
Sat, 9 Aug 2003 16:44:34 +0000 (16:44 +0000)
ext/standard/tests/array/bug24980.phpt [new file with mode: 0644]
tests/lang/bug24951.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/array/bug24980.phpt b/ext/standard/tests/array/bug24980.phpt
new file mode 100644 (file)
index 0000000..b9e04fd
--- /dev/null
@@ -0,0 +1,53 @@
+--TEST--
+Bug #24980 (array_reduce() uses first element as default running total)
+--FILE--
+<?php
+/* test #1: numeric data */
+function add_up($running_total, $current_value)
+{
+       echo "running_total is ".(int)$running_total.", current_value is {$current_value}\n";
+       $running_total += $current_value * $current_value;
+       return $running_total;
+}
+                        
+$numbers = array (2,3,5,7);
+$total = array_reduce($numbers, 'add_up');
+print "Total is $total\n";
+
+/* test #2: string data */
+$a = array("a", "b", "c");
+function foo ($a, $b)
+{
+       return $a . $b;
+}
+var_dump(array_reduce($a, "foo"));
+                        
+/* test #3: basic test (used to leak memory) */
+function rsum($v, $w)
+{
+       $v += $w;
+       return $v;
+}
+function rmul($v, $w)
+{
+       $v *= $w;
+       return $v;
+}
+$a = array(1, 2, 3, 4, 5);
+$x = array();
+$b = array_reduce($a, "rsum");
+$c = array_reduce($a, "rmul", 10);
+$d = array_reduce($x, "rsum", 1);
+
+var_dump($b, $c, $d);
+?>
+--EXPECT--
+running_total is 0, current_value is 2
+running_total is 4, current_value is 3
+running_total is 13, current_value is 5
+running_total is 38, current_value is 7
+Total is 87
+string(3) "abc"
+int(15)
+int(1200)
+int(1)
diff --git a/tests/lang/bug24951.phpt b/tests/lang/bug24951.phpt
new file mode 100644 (file)
index 0000000..aa48ab2
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+Bug #24951 (ob_flush() destroys output handler)
+--FILE--
+<?php
+function test($s, $mode)
+{
+       return (($mode & PHP_OUTPUT_HANDLER_START)?"[":"") . $s . (($mode & PHP_OUTPUT_HANDLER_END)?"]\n":"");
+}
+function t1()
+{
+       ob_start("test");
+       echo "Hello from t1 1 ";
+        echo "Hello from t1 2 ";
+        ob_end_flush();
+}
+function t2()
+{
+       ob_start("test");
+       echo "Hello from t2 1 ";
+        ob_flush();
+        echo "Hello from t2 2 ";
+        ob_end_flush();
+}
+function t3()
+{
+       ob_start("test");
+        echo "Hello from t3 1 ";
+        ob_clean();
+        echo "Hello from t3 2 ";
+        ob_end_flush();
+}
+
+t1(); echo "\n";
+t2(); echo "\n"; 
+t3(); echo "\n";
+?>
+--EXPECT--
+[Hello from t1 1 Hello from t1 2 ]
+
+[Hello from t2 1 Hello from t2 2 ]
+
+Hello from t3 2 ]