1--TEST--
2Test array_diff_key() function : usage variation - Passing unexpected values to first argument
3--FILE--
4<?php
5echo "*** Testing array_diff_key() : usage variation ***\n";
6
7// Initialise function arguments not being substituted (if any)
8$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
9$array3 = array(1, 2, 3, 4, 5);
10
11//get an unset variable
12$unset_var = 10;
13unset ($unset_var);
14
15//resource variable
16$fp = fopen(__FILE__, "r");
17
18// define some classes
19class classWithToString
20{
21    public function __toString() {
22        return "Class A object";
23    }
24}
25
26class classWithoutToString
27{
28}
29
30// heredoc string
31$heredoc = <<<EOT
32hello world
33EOT;
34
35//array of values to iterate over
36$inputs = array(
37
38      // int data
39      'int 0' => 0,
40      'int 1' => 1,
41      'int 12345' => 12345,
42      'int -12345' => -12345,
43
44      // float data
45      'float 10.5' => 10.5,
46      'float -10.5' => -10.5,
47      'float 12.3456789000e10' => 12.3456789000e10,
48      'float -12.3456789000e10' => -12.3456789000e10,
49      'float .5' => .5,
50
51      // null data
52      'uppercase NULL' => NULL,
53      'lowercase null' => null,
54
55      // boolean data
56      'lowercase true' => true,
57      'lowercase false' =>false,
58      'uppercase TRUE' =>TRUE,
59      'uppercase FALSE' =>FALSE,
60
61      // empty data
62      'empty string DQ' => "",
63      'empty string SQ' => '',
64
65      // string data
66      'string DQ' => "string",
67      'string SQ' => 'string',
68      'mixed case string' => "sTrInG",
69      'heredoc' => $heredoc,
70
71      // object data
72      'instance of classWithToString' => new classWithToString(),
73      'instance of classWithoutToString' => new classWithoutToString(),
74
75      // undefined data
76      'undefined var' => @$undefined_var,
77
78      // unset data
79      'unset var' => @$unset_var,
80
81      // resource data
82      'resource' => $fp,
83);
84
85// loop through each element of the array for array1
86foreach($inputs as $key =>$value) {
87    echo "\n--$key--\n";
88    try {
89        var_dump( array_diff_key($value, $array2) );
90    } catch (TypeError $e) {
91        echo $e->getMessage(), "\n";
92    }
93    try {
94        var_dump( array_diff_key($value, $array2, $array3) );
95    } catch (TypeError $e) {
96        echo $e->getMessage(), "\n";
97    }
98};
99
100fclose($fp);
101?>
102--EXPECT--
103*** Testing array_diff_key() : usage variation ***
104
105--int 0--
106array_diff_key(): Argument #1 ($array) must be of type array, int given
107array_diff_key(): Argument #1 ($array) must be of type array, int given
108
109--int 1--
110array_diff_key(): Argument #1 ($array) must be of type array, int given
111array_diff_key(): Argument #1 ($array) must be of type array, int given
112
113--int 12345--
114array_diff_key(): Argument #1 ($array) must be of type array, int given
115array_diff_key(): Argument #1 ($array) must be of type array, int given
116
117--int -12345--
118array_diff_key(): Argument #1 ($array) must be of type array, int given
119array_diff_key(): Argument #1 ($array) must be of type array, int given
120
121--float 10.5--
122array_diff_key(): Argument #1 ($array) must be of type array, float given
123array_diff_key(): Argument #1 ($array) must be of type array, float given
124
125--float -10.5--
126array_diff_key(): Argument #1 ($array) must be of type array, float given
127array_diff_key(): Argument #1 ($array) must be of type array, float given
128
129--float 12.3456789000e10--
130array_diff_key(): Argument #1 ($array) must be of type array, float given
131array_diff_key(): Argument #1 ($array) must be of type array, float given
132
133--float -12.3456789000e10--
134array_diff_key(): Argument #1 ($array) must be of type array, float given
135array_diff_key(): Argument #1 ($array) must be of type array, float given
136
137--float .5--
138array_diff_key(): Argument #1 ($array) must be of type array, float given
139array_diff_key(): Argument #1 ($array) must be of type array, float given
140
141--uppercase NULL--
142array_diff_key(): Argument #1 ($array) must be of type array, null given
143array_diff_key(): Argument #1 ($array) must be of type array, null given
144
145--lowercase null--
146array_diff_key(): Argument #1 ($array) must be of type array, null given
147array_diff_key(): Argument #1 ($array) must be of type array, null given
148
149--lowercase true--
150array_diff_key(): Argument #1 ($array) must be of type array, bool given
151array_diff_key(): Argument #1 ($array) must be of type array, bool given
152
153--lowercase false--
154array_diff_key(): Argument #1 ($array) must be of type array, bool given
155array_diff_key(): Argument #1 ($array) must be of type array, bool given
156
157--uppercase TRUE--
158array_diff_key(): Argument #1 ($array) must be of type array, bool given
159array_diff_key(): Argument #1 ($array) must be of type array, bool given
160
161--uppercase FALSE--
162array_diff_key(): Argument #1 ($array) must be of type array, bool given
163array_diff_key(): Argument #1 ($array) must be of type array, bool given
164
165--empty string DQ--
166array_diff_key(): Argument #1 ($array) must be of type array, string given
167array_diff_key(): Argument #1 ($array) must be of type array, string given
168
169--empty string SQ--
170array_diff_key(): Argument #1 ($array) must be of type array, string given
171array_diff_key(): Argument #1 ($array) must be of type array, string given
172
173--string DQ--
174array_diff_key(): Argument #1 ($array) must be of type array, string given
175array_diff_key(): Argument #1 ($array) must be of type array, string given
176
177--string SQ--
178array_diff_key(): Argument #1 ($array) must be of type array, string given
179array_diff_key(): Argument #1 ($array) must be of type array, string given
180
181--mixed case string--
182array_diff_key(): Argument #1 ($array) must be of type array, string given
183array_diff_key(): Argument #1 ($array) must be of type array, string given
184
185--heredoc--
186array_diff_key(): Argument #1 ($array) must be of type array, string given
187array_diff_key(): Argument #1 ($array) must be of type array, string given
188
189--instance of classWithToString--
190array_diff_key(): Argument #1 ($array) must be of type array, classWithToString given
191array_diff_key(): Argument #1 ($array) must be of type array, classWithToString given
192
193--instance of classWithoutToString--
194array_diff_key(): Argument #1 ($array) must be of type array, classWithoutToString given
195array_diff_key(): Argument #1 ($array) must be of type array, classWithoutToString given
196
197--undefined var--
198array_diff_key(): Argument #1 ($array) must be of type array, null given
199array_diff_key(): Argument #1 ($array) must be of type array, null given
200
201--unset var--
202array_diff_key(): Argument #1 ($array) must be of type array, null given
203array_diff_key(): Argument #1 ($array) must be of type array, null given
204
205--resource--
206array_diff_key(): Argument #1 ($array) must be of type array, resource given
207array_diff_key(): Argument #1 ($array) must be of type array, resource given
208