1--TEST--
2Test array_diff_key() function : usage variation - Passing unexpected values to second argument
3--FILE--
4<?php
5echo "*** Testing array_diff_key() : usage variation ***\n";
6
7// Initialise function arguments not being substituted (if any)
8$array1 = 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
86
87foreach($inputs as $key =>$value) {
88    echo "\n--$key--\n";
89    try {
90        var_dump( array_diff_key($array1, $value) );
91    } catch (TypeError $e) {
92        echo $e->getMessage(), "\n";
93    }
94    try {
95        var_dump( array_diff_key($array1, $value, $array3) );
96    } catch (TypeError $e) {
97        echo $e->getMessage(), "\n";
98    }
99};
100
101fclose($fp);
102?>
103--EXPECT--
104*** Testing array_diff_key() : usage variation ***
105
106--int 0--
107array_diff_key(): Argument #2 must be of type array, int given
108array_diff_key(): Argument #2 must be of type array, int given
109
110--int 1--
111array_diff_key(): Argument #2 must be of type array, int given
112array_diff_key(): Argument #2 must be of type array, int given
113
114--int 12345--
115array_diff_key(): Argument #2 must be of type array, int given
116array_diff_key(): Argument #2 must be of type array, int given
117
118--int -12345--
119array_diff_key(): Argument #2 must be of type array, int given
120array_diff_key(): Argument #2 must be of type array, int given
121
122--float 10.5--
123array_diff_key(): Argument #2 must be of type array, float given
124array_diff_key(): Argument #2 must be of type array, float given
125
126--float -10.5--
127array_diff_key(): Argument #2 must be of type array, float given
128array_diff_key(): Argument #2 must be of type array, float given
129
130--float 12.3456789000e10--
131array_diff_key(): Argument #2 must be of type array, float given
132array_diff_key(): Argument #2 must be of type array, float given
133
134--float -12.3456789000e10--
135array_diff_key(): Argument #2 must be of type array, float given
136array_diff_key(): Argument #2 must be of type array, float given
137
138--float .5--
139array_diff_key(): Argument #2 must be of type array, float given
140array_diff_key(): Argument #2 must be of type array, float given
141
142--uppercase NULL--
143array_diff_key(): Argument #2 must be of type array, null given
144array_diff_key(): Argument #2 must be of type array, null given
145
146--lowercase null--
147array_diff_key(): Argument #2 must be of type array, null given
148array_diff_key(): Argument #2 must be of type array, null given
149
150--lowercase true--
151array_diff_key(): Argument #2 must be of type array, bool given
152array_diff_key(): Argument #2 must be of type array, bool given
153
154--lowercase false--
155array_diff_key(): Argument #2 must be of type array, bool given
156array_diff_key(): Argument #2 must be of type array, bool given
157
158--uppercase TRUE--
159array_diff_key(): Argument #2 must be of type array, bool given
160array_diff_key(): Argument #2 must be of type array, bool given
161
162--uppercase FALSE--
163array_diff_key(): Argument #2 must be of type array, bool given
164array_diff_key(): Argument #2 must be of type array, bool given
165
166--empty string DQ--
167array_diff_key(): Argument #2 must be of type array, string given
168array_diff_key(): Argument #2 must be of type array, string given
169
170--empty string SQ--
171array_diff_key(): Argument #2 must be of type array, string given
172array_diff_key(): Argument #2 must be of type array, string given
173
174--string DQ--
175array_diff_key(): Argument #2 must be of type array, string given
176array_diff_key(): Argument #2 must be of type array, string given
177
178--string SQ--
179array_diff_key(): Argument #2 must be of type array, string given
180array_diff_key(): Argument #2 must be of type array, string given
181
182--mixed case string--
183array_diff_key(): Argument #2 must be of type array, string given
184array_diff_key(): Argument #2 must be of type array, string given
185
186--heredoc--
187array_diff_key(): Argument #2 must be of type array, string given
188array_diff_key(): Argument #2 must be of type array, string given
189
190--instance of classWithToString--
191array_diff_key(): Argument #2 must be of type array, classWithToString given
192array_diff_key(): Argument #2 must be of type array, classWithToString given
193
194--instance of classWithoutToString--
195array_diff_key(): Argument #2 must be of type array, classWithoutToString given
196array_diff_key(): Argument #2 must be of type array, classWithoutToString given
197
198--undefined var--
199array_diff_key(): Argument #2 must be of type array, null given
200array_diff_key(): Argument #2 must be of type array, null given
201
202--unset var--
203array_diff_key(): Argument #2 must be of type array, null given
204array_diff_key(): Argument #2 must be of type array, null given
205
206--resource--
207array_diff_key(): Argument #2 must be of type array, resource given
208array_diff_key(): Argument #2 must be of type array, resource given
209