1--TEST--
2Test array_diff_uassoc() function : usage variation -Passing unexpected values as third optional argument
3--FILE--
4<?php
5/* Prototype  : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
6 * Description: Computes the difference of arrays with additional index check which is performed by a
7 * 				user supplied callback function
8 * Source code: ext/standard/array.c
9 */
10
11echo "*** Testing array_diff_uassoc() : usage variation ***\n";
12
13//Initialize variables
14$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
15$array2 = array("a" => "green", "yellow", "red");
16
17
18function key_compare_func($a, $b)
19{
20    if ($a === $b) {
21        return 0;
22    }
23    return ($a > $b)? 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// add arrays
51$index_array = array (1, 2, 3);
52$assoc_array = array ('one' => 1, 'two' => 2);
53
54//array of values to iterate over
55$inputs = array(
56
57      // int data
58      'int 0' => 0,
59      'int 1' => 1,
60      'int 12345' => 12345,
61      'int -12345' => -12345,
62
63      // float data
64      'float 10.5' => 10.5,
65      'float -10.5' => -10.5,
66      'float 12.3456789000e10' => 12.3456789000e10,
67      'float -12.3456789000e10' => -12.3456789000e10,
68      'float .5' => .5,
69
70      // null data
71      'uppercase NULL' => NULL,
72      'lowercase null' => null,
73
74      // boolean data
75      'lowercase true' => true,
76      'lowercase false' =>false,
77      'uppercase TRUE' =>TRUE,
78      'uppercase FALSE' =>FALSE,
79
80      // empty data
81      'empty string DQ' => "",
82      'empty string SQ' => '',
83
84      // string data
85      'string DQ' => "string",
86      'string SQ' => 'string',
87      'mixed case string' => "sTrInG",
88      'heredoc' => $heredoc,
89
90      // object data
91      'instance of classWithToString' => new classWithToString(),
92      'instance of classWithoutToString' => new classWithoutToString(),
93
94      // undefined data
95      'undefined var' => @$undefined_var,
96
97      // unset data
98      'unset var' => @$unset_var,
99
100      // resource data
101      'resource' => $fp,
102);
103
104// loop through each element of the array for arr2
105
106foreach($inputs as $key =>$value) {
107      echo "\n--$key--\n";
108      var_dump( array_diff_uassoc($array1, $array2, $value,  "key_compare_func") );
109};
110
111fclose($fp);
112?>
113===DONE===
114--EXPECTF--
115*** Testing array_diff_uassoc() : usage variation ***
116
117--int 0--
118
119Warning: array_diff_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d
120NULL
121
122--int 1--
123
124Warning: array_diff_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d
125NULL
126
127--int 12345--
128
129Warning: array_diff_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d
130NULL
131
132--int -12345--
133
134Warning: array_diff_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d
135NULL
136
137--float 10.5--
138
139Warning: array_diff_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d
140NULL
141
142--float -10.5--
143
144Warning: array_diff_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d
145NULL
146
147--float 12.3456789000e10--
148
149Warning: array_diff_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d
150NULL
151
152--float -12.3456789000e10--
153
154Warning: array_diff_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d
155NULL
156
157--float .5--
158
159Warning: array_diff_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d
160NULL
161
162--uppercase NULL--
163
164Warning: array_diff_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d
165NULL
166
167--lowercase null--
168
169Warning: array_diff_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d
170NULL
171
172--lowercase true--
173
174Warning: array_diff_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d
175NULL
176
177--lowercase false--
178
179Warning: array_diff_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d
180NULL
181
182--uppercase TRUE--
183
184Warning: array_diff_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d
185NULL
186
187--uppercase FALSE--
188
189Warning: array_diff_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d
190NULL
191
192--empty string DQ--
193
194Warning: array_diff_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d
195NULL
196
197--empty string SQ--
198
199Warning: array_diff_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d
200NULL
201
202--string DQ--
203
204Warning: array_diff_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d
205NULL
206
207--string SQ--
208
209Warning: array_diff_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d
210NULL
211
212--mixed case string--
213
214Warning: array_diff_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d
215NULL
216
217--heredoc--
218
219Warning: array_diff_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d
220NULL
221
222--instance of classWithToString--
223
224Warning: array_diff_uassoc(): Expected parameter 3 to be an array, object given in %s on line %d
225NULL
226
227--instance of classWithoutToString--
228
229Warning: array_diff_uassoc(): Expected parameter 3 to be an array, object given in %s on line %d
230NULL
231
232--undefined var--
233
234Warning: array_diff_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d
235NULL
236
237--unset var--
238
239Warning: array_diff_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d
240NULL
241
242--resource--
243
244Warning: array_diff_uassoc(): Expected parameter 3 to be an array, resource given in %s on line %d
245NULL
246===DONE===
247