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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
--TEST--
Test array_walk_recursive() function : error conditions - callback parameters
--FILE--
<?php
/*
* Testing array_walk_recursive() by passing more number of parameters to callback function
*/
$input = array(1);
function callback1($value, $key, $user_data ) {
echo "\ncallback1() invoked \n";
}
function callback2($value, $key, $user_data1, $user_data2) {
echo "\ncallback2() invoked \n";
}
echo "*** Testing array_walk_recursive() : error conditions - callback parameters ***\n";
// expected: Missing argument Warning
try {
var_dump( array_walk_recursive($input, "callback1") );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
try {
var_dump( array_walk_recursive($input, "callback2", 4) );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
// expected: Warning is suppressed
try {
var_dump( @array_walk_recursive($input, "callback1") );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
try {
var_dump( @array_walk_recursive($input, "callback2", 4) );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
echo "-- Testing array_walk_recursive() function with too many callback parameters --\n";
try {
var_dump( array_walk_recursive($input, "callback1", 20, 10) );
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
echo "Done";
?>
--EXPECT--
*** Testing array_walk_recursive() : error conditions - callback parameters ***
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
-- Testing array_walk_recursive() function with too many callback parameters --
Exception: array_walk_recursive() expects at most 3 parameters, 4 given
Done
|