1--TEST--
2Test array_walk() function : error conditions - callback parameters
3--FILE--
4<?php
5/*
6 * Testing array_walk() by passing more number of parameters to callback function
7 */
8$input = array(1);
9
10function callback1($value, $key, $user_data ) {
11  echo "\ncallback1() invoked \n";
12}
13
14function callback2($value, $key, $user_data1, $user_data2) {
15  echo "\ncallback2() invoked \n";
16}
17echo "*** Testing array_walk() : error conditions - callback parameters ***\n";
18
19// expected: Missing argument Warning
20try {
21    var_dump( array_walk($input, "callback1") );
22} catch (Throwable $e) {
23    echo "Exception: " . $e->getMessage() . "\n";
24}
25try {
26    var_dump( array_walk($input, "callback2", 4) );
27} catch (Throwable $e) {
28    echo "Exception: " . $e->getMessage() . "\n";
29}
30
31// expected: Warning is suppressed
32try {
33    var_dump( @array_walk($input, "callback1") );
34} catch (Throwable $e) {
35    echo "Exception: " . $e->getMessage() . "\n";
36}
37try {
38    var_dump( @array_walk($input, "callback2", 4) );
39} catch (Throwable $e) {
40    echo "Exception: " . $e->getMessage() . "\n";
41}
42
43echo "-- Testing array_walk() function with too many callback parameters --\n";
44try {
45    var_dump( array_walk($input, "callback1", 20, 10) );
46} catch (Throwable $e) {
47    echo "Exception: " . $e->getMessage() . "\n";
48}
49
50echo "Done";
51?>
52--EXPECT--
53*** Testing array_walk() : error conditions - callback parameters ***
54Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
55Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
56Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
57Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
58-- Testing array_walk() function with too many callback parameters --
59Exception: array_walk() expects at most 3 arguments, 4 given
60Done
61