1--TEST--
2Test array_walk() function : error conditions - callback parameters
3--FILE--
4<?php
5/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
6 * Description: Apply a user function to every member of an array
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * Testing array_walk() by passing more number of parameters to callback function
12 */
13$input = array(1);
14
15function callback1($value, $key, $user_data ) {
16  echo "\ncallback1() invoked \n";
17}
18
19function callback2($value, $key, $user_data1, $user_data2) {
20  echo "\ncallback2() invoked \n";
21}
22echo "*** Testing array_walk() : error conditions - callback parameters ***\n";
23
24// expected: Missing argument Warning
25try {
26	var_dump( array_walk($input, "callback1") );
27} catch (Throwable $e) {
28	echo "Exception: " . $e->getMessage() . "\n";
29}
30try {
31	var_dump( array_walk($input, "callback2", 4) );
32} catch (Throwable $e) {
33	echo "Exception: " . $e->getMessage() . "\n";
34}
35
36// expected: Warning is suppressed
37try {
38	var_dump( @array_walk($input, "callback1") );
39} catch (Throwable $e) {
40	echo "Exception: " . $e->getMessage() . "\n";
41}
42try {
43	var_dump( @array_walk($input, "callback2", 4) );
44} catch (Throwable $e) {
45	echo "Exception: " . $e->getMessage() . "\n";
46}
47
48echo "-- Testing array_walk() function with too many callback parameters --\n";
49try {
50	var_dump( array_walk($input, "callback1", 20, 10) );
51} catch (Throwable $e) {
52	echo "Exception: " . $e->getMessage() . "\n";
53}
54
55echo "Done";
56?>
57--EXPECTF--
58*** Testing array_walk() : error conditions - callback parameters ***
59Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
60Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
61Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
62Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
63-- Testing array_walk() function with too many callback parameters --
64
65Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d
66NULL
67Done
68