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