]> granicus.if.org Git - php/blob
889c5ce1b2
[php] /
1 --TEST--
2 Test array_diff() function : error conditions - too few arguments passed to function
3 --FILE--
4 <?php
5 /* Prototype  : array array_diff(array $arr1, array $arr2 [, array ...])
6  * Description: Returns the entries of $arr1 that have values which are
7  * not present in any of the others arguments.
8  * Source code: ext/standard/array.c
9  */
10
11 /*
12  * Test array_diff with less than the expected number of arguments
13  */
14
15 echo "*** Testing array_diff() : error conditions ***\n";
16 // Zero arguments
17 echo "\n-- Testing array_diff() function with zero arguments --\n";
18 try {
19     var_dump( array_diff() );
20 } catch (ArgumentCountError $e) {
21     echo $e->getMessage(), "\n";
22 }
23
24
25 // Testing array_diff with one less than the expected number of arguments
26 echo "\n-- Testing array_diff() function with less than expected no. of arguments --\n";
27 $arr1 = array(1, 2);
28 try {
29     var_dump( array_diff($arr1) );
30 } catch (ArgumentCountError $e) {
31     echo $e->getMessage(), "\n";
32 }
33
34 echo "Done";
35 ?>
36 --EXPECT--
37 *** Testing array_diff() : error conditions ***
38
39 -- Testing array_diff() function with zero arguments --
40 At least 2 parameters are required, 0 given
41
42 -- Testing array_diff() function with less than expected no. of arguments --
43 At least 2 parameters are required, 1 given
44 Done