1--TEST--
2Test ksort() function : usage variations - unexpected values for 'array' argument
3--FILE--
4<?php
5/* Prototype  : bool ksort(array &array [, int sort_flags])
6 * Description: Sort an array by key, maintaining key to data correlation
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * testing ksort() by providing different unexpected values for array argument with following flag values:
12 *  1. flag value as defualt
13 *  2. SORT_REGULAR - compare items normally
14 *  3. SORT_NUMERIC - compare items numerically
15 *  4. SORT_STRING - compare items as strings
16*/
17
18echo "*** Testing ksort() : usage variations ***\n";
19
20// get an unset variable
21$unset_var = 10;
22unset ($unset_var);
23
24// resource variable
25$fp = fopen(__FILE__, "r");
26
27$unexpected_values = array (
28
29        // int data
30/*1*/   0,
31        1,
32        12345,
33        -2345,
34
35        // float data
36/*5*/   10.5,
37        -10.5,
38        10.5e3,
39        10.6E-2,
40        0.5,
41
42        // null data
43/*10*/  NULL,
44        null,
45
46        // boolean data
47/*11*/  true,
48        false,
49        TRUE,
50        FALSE,
51
52        // empty data
53/*15*/  "",
54        '',
55
56        // string data
57/*17*/  "string",
58        'string',
59
60        // object data
61/*19*/  new stdclass(),
62
63        // undefined data
64/*20*/  @undefined_var,
65
66        // unset data
67/*21*/  @unset_var,
68
69        // resource variable
70/*22*/  $fp
71
72);
73
74// loop though each element of the array and check the working of ksort()
75// when $array argument is supplied with different values from $unexpected_values
76echo "\n-- Testing ksort() by supplying different unexpected values for 'array' argument --\n";
77echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n";
78
79$counter = 1;
80for($index = 0; $index < count($unexpected_values); $index ++) {
81  echo "-- Iteration $counter --\n";
82  $value = $unexpected_values [$index];
83  var_dump( ksort($value) ); // expecting : bool(false)
84  var_dump( ksort($value, SORT_REGULAR) ); // expecting : bool(false)
85  var_dump( ksort($value, SORT_NUMERIC) ); // expecting : bool(false)
86  var_dump( ksort($value, SORT_STRING) ); // expecting : bool(false)
87  $counter++;
88}
89
90echo "Done";
91?>
92--EXPECTF--
93*** Testing ksort() : usage variations ***
94
95-- Testing ksort() by supplying different unexpected values for 'array' argument --
96
97-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --
98-- Iteration 1 --
99
100Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
101bool(false)
102
103Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
104bool(false)
105
106Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
107bool(false)
108
109Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
110bool(false)
111-- Iteration 2 --
112
113Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
114bool(false)
115
116Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
117bool(false)
118
119Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
120bool(false)
121
122Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
123bool(false)
124-- Iteration 3 --
125
126Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
127bool(false)
128
129Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
130bool(false)
131
132Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
133bool(false)
134
135Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
136bool(false)
137-- Iteration 4 --
138
139Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
140bool(false)
141
142Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
143bool(false)
144
145Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
146bool(false)
147
148Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d
149bool(false)
150-- Iteration 5 --
151
152Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
153bool(false)
154
155Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
156bool(false)
157
158Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
159bool(false)
160
161Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
162bool(false)
163-- Iteration 6 --
164
165Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
166bool(false)
167
168Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
169bool(false)
170
171Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
172bool(false)
173
174Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
175bool(false)
176-- Iteration 7 --
177
178Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
179bool(false)
180
181Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
182bool(false)
183
184Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
185bool(false)
186
187Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
188bool(false)
189-- Iteration 8 --
190
191Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
192bool(false)
193
194Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
195bool(false)
196
197Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
198bool(false)
199
200Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
201bool(false)
202-- Iteration 9 --
203
204Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
205bool(false)
206
207Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
208bool(false)
209
210Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
211bool(false)
212
213Warning: ksort() expects parameter 1 to be array, float given in %s on line %d
214bool(false)
215-- Iteration 10 --
216
217Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
218bool(false)
219
220Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
221bool(false)
222
223Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
224bool(false)
225
226Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
227bool(false)
228-- Iteration 11 --
229
230Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
231bool(false)
232
233Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
234bool(false)
235
236Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
237bool(false)
238
239Warning: ksort() expects parameter 1 to be array, null given in %s on line %d
240bool(false)
241-- Iteration 12 --
242
243Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
244bool(false)
245
246Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
247bool(false)
248
249Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
250bool(false)
251
252Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
253bool(false)
254-- Iteration 13 --
255
256Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
257bool(false)
258
259Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
260bool(false)
261
262Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
263bool(false)
264
265Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
266bool(false)
267-- Iteration 14 --
268
269Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
270bool(false)
271
272Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
273bool(false)
274
275Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
276bool(false)
277
278Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
279bool(false)
280-- Iteration 15 --
281
282Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
283bool(false)
284
285Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
286bool(false)
287
288Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
289bool(false)
290
291Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d
292bool(false)
293-- Iteration 16 --
294
295Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
296bool(false)
297
298Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
299bool(false)
300
301Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
302bool(false)
303
304Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
305bool(false)
306-- Iteration 17 --
307
308Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
309bool(false)
310
311Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
312bool(false)
313
314Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
315bool(false)
316
317Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
318bool(false)
319-- Iteration 18 --
320
321Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
322bool(false)
323
324Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
325bool(false)
326
327Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
328bool(false)
329
330Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
331bool(false)
332-- Iteration 19 --
333
334Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
335bool(false)
336
337Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
338bool(false)
339
340Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
341bool(false)
342
343Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
344bool(false)
345-- Iteration 20 --
346
347Warning: ksort() expects parameter 1 to be array, object given in %s on line %d
348bool(false)
349
350Warning: ksort() expects parameter 1 to be array, object given in %s on line %d
351bool(false)
352
353Warning: ksort() expects parameter 1 to be array, object given in %s on line %d
354bool(false)
355
356Warning: ksort() expects parameter 1 to be array, object given in %s on line %d
357bool(false)
358-- Iteration 21 --
359
360Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
361bool(false)
362
363Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
364bool(false)
365
366Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
367bool(false)
368
369Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
370bool(false)
371-- Iteration 22 --
372
373Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
374bool(false)
375
376Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
377bool(false)
378
379Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
380bool(false)
381
382Warning: ksort() expects parameter 1 to be array, string given in %s on line %d
383bool(false)
384-- Iteration 23 --
385
386Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d
387bool(false)
388
389Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d
390bool(false)
391
392Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d
393bool(false)
394
395Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d
396bool(false)
397Done
398