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