TypePHP 编译器 https://swoole.com/aot/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

52 lines
1.2 KiB

--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;
}
function foo($a, $b)
{
return $a . $b;
}
/* test #3: basic test (used to leak memory) */
function rsum($v, $w)
{
$v += $w;
return $v;
}
function rmul($v, $w)
{
$v *= $w;
return $v;
}
function main()
{
$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");
var_dump(array_reduce($a, "foo"));
$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)