1--TEST--
2Test array_intersect_ukey() function : usage variation - Passing unexpected values to optional third argument
3--FILE--
4<?php
5/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
6 * Description: Computes the intersection of arrays using a callback function on the keys for comparison.
7 * Source code: ext/standard/array.c
8 */
9
10echo "*** Testing array_intersect_ukey() : usage variation ***\n";
11
12//Initialise arguments
13$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
14$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);
15$array4 = array('green' => 5, 'cyan'   => 8);
16
17//Call back function
18function key_compare_func($key1, $key2)
19{
20    if ($key1 == $key2)
21        return 0;
22    else
23        return ($key1 > $key2)? 1:-1;
24}
25
26//get an unset variable
27$unset_var = 10;
28unset ($unset_var);
29
30//resource variable
31$fp = fopen(__FILE__, "r");
32
33// define some classes
34class classWithToString
35{
36	public function __toString() {
37		return "Class A object";
38	}
39}
40
41class classWithoutToString
42{
43}
44
45// heredoc string
46$heredoc = <<<EOT
47hello world
48EOT;
49
50//array of values to iterate over
51$inputs = array(
52
53      // int data
54      'int 0' => 0,
55      'int 1' => 1,
56      'int 12345' => 12345,
57      'int -12345' => -12345,
58
59      // float data
60      'float 10.5' => 10.5,
61      'float -10.5' => -10.5,
62      'float 12.3456789000e10' => 12.3456789000e10,
63      'float -12.3456789000e10' => -12.3456789000e10,
64      'float .5' => .5,
65
66      // null data
67      'uppercase NULL' => NULL,
68      'lowercase null' => null,
69
70      // boolean data
71      'lowercase true' => true,
72      'lowercase false' =>false,
73      'uppercase TRUE' =>TRUE,
74      'uppercase FALSE' =>FALSE,
75
76      // empty data
77      'empty string DQ' => "",
78      'empty string SQ' => '',
79
80      // string data
81      'string DQ' => "string",
82      'string SQ' => 'string',
83      'mixed case string' => "sTrInG",
84      'heredoc' => $heredoc,
85
86      // object data
87      'instance of classWithToString' => new classWithToString(),
88      'instance of classWithoutToString' => new classWithoutToString(),
89
90      // undefined data
91      'undefined var' => @$undefined_var,
92
93      // unset data
94      'unset var' => @$unset_var,
95
96      // resource data
97      'resource var' => $fp,
98);
99
100// loop through each element of the array for arr2
101
102foreach($inputs as $key =>$value) {
103      echo "\n--$key--\n";
104      var_dump( array_intersect_ukey($array1, $array2, $value, 'key_compare_func') );
105      var_dump( array_intersect_ukey($array1, $array2, $value, $array4, 'key_compare_func') );
106};
107
108fclose($fp);
109?>
110===DONE===
111--EXPECTF--
112*** Testing array_intersect_ukey() : usage variation ***
113
114--int 0--
115
116Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
117NULL
118
119Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
120NULL
121
122--int 1--
123
124Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
125NULL
126
127Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
128NULL
129
130--int 12345--
131
132Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
133NULL
134
135Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
136NULL
137
138--int -12345--
139
140Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
141NULL
142
143Warning: array_intersect_ukey(): Expected parameter 3 to be an array, int given in %s on line %d
144NULL
145
146--float 10.5--
147
148Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
149NULL
150
151Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
152NULL
153
154--float -10.5--
155
156Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
157NULL
158
159Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
160NULL
161
162--float 12.3456789000e10--
163
164Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
165NULL
166
167Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
168NULL
169
170--float -12.3456789000e10--
171
172Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
173NULL
174
175Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
176NULL
177
178--float .5--
179
180Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
181NULL
182
183Warning: array_intersect_ukey(): Expected parameter 3 to be an array, float given in %s on line %d
184NULL
185
186--uppercase NULL--
187
188Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
189NULL
190
191Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
192NULL
193
194--lowercase null--
195
196Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
197NULL
198
199Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
200NULL
201
202--lowercase true--
203
204Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
205NULL
206
207Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
208NULL
209
210--lowercase false--
211
212Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
213NULL
214
215Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
216NULL
217
218--uppercase TRUE--
219
220Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
221NULL
222
223Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
224NULL
225
226--uppercase FALSE--
227
228Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
229NULL
230
231Warning: array_intersect_ukey(): Expected parameter 3 to be an array, bool given in %s on line %d
232NULL
233
234--empty string DQ--
235
236Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
237NULL
238
239Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
240NULL
241
242--empty string SQ--
243
244Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
245NULL
246
247Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
248NULL
249
250--string DQ--
251
252Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
253NULL
254
255Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
256NULL
257
258--string SQ--
259
260Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
261NULL
262
263Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
264NULL
265
266--mixed case string--
267
268Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
269NULL
270
271Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
272NULL
273
274--heredoc--
275
276Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
277NULL
278
279Warning: array_intersect_ukey(): Expected parameter 3 to be an array, string given in %s on line %d
280NULL
281
282--instance of classWithToString--
283
284Warning: array_intersect_ukey(): Expected parameter 3 to be an array, object given in %s on line %d
285NULL
286
287Warning: array_intersect_ukey(): Expected parameter 3 to be an array, object given in %s on line %d
288NULL
289
290--instance of classWithoutToString--
291
292Warning: array_intersect_ukey(): Expected parameter 3 to be an array, object given in %s on line %d
293NULL
294
295Warning: array_intersect_ukey(): Expected parameter 3 to be an array, object given in %s on line %d
296NULL
297
298--undefined var--
299
300Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
301NULL
302
303Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
304NULL
305
306--unset var--
307
308Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
309NULL
310
311Warning: array_intersect_ukey(): Expected parameter 3 to be an array, null given in %s on line %d
312NULL
313
314--resource var--
315
316Warning: array_intersect_ukey(): Expected parameter 3 to be an array, resource given in %s on line %d
317NULL
318
319Warning: array_intersect_ukey(): Expected parameter 3 to be an array, resource given in %s on line %d
320NULL
321===DONE===
322