]> granicus.if.org Git - php/blob
e957abce1c
[php] /
1 --TEST--
2 Test array_diff_key() function : error conditions
3 --FILE--
4 <?php
5 /* Prototype  : array array_diff_key(array arr1, array arr2 [, array ...])
6  * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments.
7  * Source code: ext/standard/array.c
8  */
9
10 echo "*** Testing array_diff_key() : error conditions ***\n";
11
12 // Initialise the variables
13 $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
14
15 // Testing array_diff_key with one less than the expected number of arguments
16 echo "\n-- Testing array_diff_key() function with less than expected no. of arguments --\n";
17 try {
18     var_dump( array_diff_key($array1) );
19 } catch (TypeError $e) {
20     echo $e->getMessage(), "\n";
21 }
22
23 // Testing array_diff_key with no arguments
24 echo "\n-- Testing array_diff_key() function with no arguments --\n";
25 try {
26     var_dump( array_diff_key() );
27 } catch (ArgumentCountError $e) {
28     echo $e->getMessage(), "\n";
29 }
30 ?>
31 --EXPECTF--
32 *** Testing array_diff_key() : error conditions ***
33
34 -- Testing array_diff_key() function with less than expected no. of arguments --
35 At least 2 parameters are required, 1 given
36
37 -- Testing array_diff_key() function with no arguments --
38 At least 2 parameters are required, 0 given