summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_reduce_variation1.phpt
blob: 96268f66056f094a79bf1e5ffbbfefe828d7aeb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--TEST--
Test array_reduce() function : variation
--FILE--
<?php
/* Prototype  : mixed array_reduce(array input, mixed callback [, int initial])
 * Description: Iteratively reduce the array to a single value via the callback.
 * Source code: ext/standard/array.c
 * Alias to functions:
 */

echo "*** Testing array_reduce() : variation ***\n";


function oneArg($v) {
  return $v;
}

function threeArgs($v, $w, $x) {
  return $v + $w + $x;
}

$array = array(1);

echo "\n--- Testing with a callback with too few parameters ---\n";
var_dump(array_reduce($array, "oneArg", 2));

echo "\n--- Testing with a callback with too many parameters ---\n";
try {
	var_dump(array_reduce($array, "threeArgs", 2));
} catch (Throwable $e) {
	echo "Exception: " . $e->getMessage() . "\n";
}

?>
===DONE===
--EXPECTF--
*** Testing array_reduce() : variation ***

--- Testing with a callback with too few parameters ---
int(2)

--- Testing with a callback with too many parameters ---
Exception: Too few arguments to function threeArgs(), 2 passed and exactly 3 expected
===DONE===