1--TEST--
2Test rsort() function : usage variations - Pass different data types as $array_arg arg
3--FILE--
4<?php
5/* Prototype  : bool rsort(array &$array_arg [, int $sort_flags])
6 * Description: Sort an array in reverse order
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * Pass different data types as $array_arg argument to rsort() to test behaviour
12 */
13
14echo "*** Testing rsort() : variation ***\n";
15
16//get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20// get a class
21class classA
22{
23  public function __toString() {
24    return "Class A object";
25  }
26}
27
28// heredoc string
29$heredoc = <<<EOT
30hello world
31EOT;
32
33// get a resource variable
34$fp = fopen(__FILE__, "r");
35
36// unexpected values to be passed to $array_arg argument
37$inputs = array(
38
39       // int data
40/*1*/  0,
41       1,
42       12345,
43       -2345,
44
45       // float data
46/*5*/  10.5,
47       -10.5,
48       12.3456789000e10,
49       12.3456789000E-10,
50       .5,
51
52       // null data
53/*10*/ NULL,
54       null,
55
56       // boolean data
57/*12*/ true,
58       false,
59       TRUE,
60       FALSE,
61
62       // empty data
63/*16*/ "",
64       '',
65
66       // string data
67/*18*/ "string",
68       'string',
69       $heredoc,
70
71       // object data
72/*21*/ new classA(),
73
74       // undefined data
75/*22*/ @$undefined_var,
76
77       // unset data
78/*23*/ @$unset_var,
79
80       // resource variable
81/*24*/ $fp
82);
83
84// loop through each element of $inputs to check the behavior of rsort()
85$iterator = 1;
86foreach ($inputs as $input) {
87  echo "-- Iteration $iterator --\n";
88  echo "Flag = default:\n";
89  var_dump( rsort($input) );
90  echo "Flag = SORT_REGULAR:\n";
91  var_dump( rsort($input, SORT_REGULAR) );
92  echo "Flag = SORT_NUMERIC:\n";
93  var_dump( rsort($input, SORT_NUMERIC) );
94  echo "Flag = SORT_STRING:\n";
95  var_dump( rsort($input, SORT_STRING) );
96  $iterator++;
97}
98
99fclose($fp);
100
101echo "Done";
102?>
103--EXPECTF--
104*** Testing rsort() : variation ***
105-- Iteration 1 --
106Flag = default:
107
108Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
109bool(false)
110Flag = SORT_REGULAR:
111
112Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
113bool(false)
114Flag = SORT_NUMERIC:
115
116Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
117bool(false)
118Flag = SORT_STRING:
119
120Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
121bool(false)
122-- Iteration 2 --
123Flag = default:
124
125Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
126bool(false)
127Flag = SORT_REGULAR:
128
129Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
130bool(false)
131Flag = SORT_NUMERIC:
132
133Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
134bool(false)
135Flag = SORT_STRING:
136
137Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
138bool(false)
139-- Iteration 3 --
140Flag = default:
141
142Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
143bool(false)
144Flag = SORT_REGULAR:
145
146Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
147bool(false)
148Flag = SORT_NUMERIC:
149
150Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
151bool(false)
152Flag = SORT_STRING:
153
154Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
155bool(false)
156-- Iteration 4 --
157Flag = default:
158
159Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
160bool(false)
161Flag = SORT_REGULAR:
162
163Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
164bool(false)
165Flag = SORT_NUMERIC:
166
167Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
168bool(false)
169Flag = SORT_STRING:
170
171Warning: rsort() expects parameter 1 to be array, int given in %s on line %d
172bool(false)
173-- Iteration 5 --
174Flag = default:
175
176Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
177bool(false)
178Flag = SORT_REGULAR:
179
180Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
181bool(false)
182Flag = SORT_NUMERIC:
183
184Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
185bool(false)
186Flag = SORT_STRING:
187
188Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
189bool(false)
190-- Iteration 6 --
191Flag = default:
192
193Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
194bool(false)
195Flag = SORT_REGULAR:
196
197Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
198bool(false)
199Flag = SORT_NUMERIC:
200
201Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
202bool(false)
203Flag = SORT_STRING:
204
205Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
206bool(false)
207-- Iteration 7 --
208Flag = default:
209
210Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
211bool(false)
212Flag = SORT_REGULAR:
213
214Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
215bool(false)
216Flag = SORT_NUMERIC:
217
218Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
219bool(false)
220Flag = SORT_STRING:
221
222Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
223bool(false)
224-- Iteration 8 --
225Flag = default:
226
227Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
228bool(false)
229Flag = SORT_REGULAR:
230
231Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
232bool(false)
233Flag = SORT_NUMERIC:
234
235Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
236bool(false)
237Flag = SORT_STRING:
238
239Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
240bool(false)
241-- Iteration 9 --
242Flag = default:
243
244Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
245bool(false)
246Flag = SORT_REGULAR:
247
248Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
249bool(false)
250Flag = SORT_NUMERIC:
251
252Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
253bool(false)
254Flag = SORT_STRING:
255
256Warning: rsort() expects parameter 1 to be array, float given in %s on line %d
257bool(false)
258-- Iteration 10 --
259Flag = default:
260
261Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
262bool(false)
263Flag = SORT_REGULAR:
264
265Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
266bool(false)
267Flag = SORT_NUMERIC:
268
269Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
270bool(false)
271Flag = SORT_STRING:
272
273Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
274bool(false)
275-- Iteration 11 --
276Flag = default:
277
278Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
279bool(false)
280Flag = SORT_REGULAR:
281
282Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
283bool(false)
284Flag = SORT_NUMERIC:
285
286Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
287bool(false)
288Flag = SORT_STRING:
289
290Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
291bool(false)
292-- Iteration 12 --
293Flag = default:
294
295Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
296bool(false)
297Flag = SORT_REGULAR:
298
299Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
300bool(false)
301Flag = SORT_NUMERIC:
302
303Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
304bool(false)
305Flag = SORT_STRING:
306
307Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
308bool(false)
309-- Iteration 13 --
310Flag = default:
311
312Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
313bool(false)
314Flag = SORT_REGULAR:
315
316Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
317bool(false)
318Flag = SORT_NUMERIC:
319
320Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
321bool(false)
322Flag = SORT_STRING:
323
324Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
325bool(false)
326-- Iteration 14 --
327Flag = default:
328
329Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
330bool(false)
331Flag = SORT_REGULAR:
332
333Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
334bool(false)
335Flag = SORT_NUMERIC:
336
337Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
338bool(false)
339Flag = SORT_STRING:
340
341Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
342bool(false)
343-- Iteration 15 --
344Flag = default:
345
346Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
347bool(false)
348Flag = SORT_REGULAR:
349
350Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
351bool(false)
352Flag = SORT_NUMERIC:
353
354Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
355bool(false)
356Flag = SORT_STRING:
357
358Warning: rsort() expects parameter 1 to be array, bool given in %s on line %d
359bool(false)
360-- Iteration 16 --
361Flag = default:
362
363Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
364bool(false)
365Flag = SORT_REGULAR:
366
367Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
368bool(false)
369Flag = SORT_NUMERIC:
370
371Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
372bool(false)
373Flag = SORT_STRING:
374
375Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
376bool(false)
377-- Iteration 17 --
378Flag = default:
379
380Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
381bool(false)
382Flag = SORT_REGULAR:
383
384Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
385bool(false)
386Flag = SORT_NUMERIC:
387
388Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
389bool(false)
390Flag = SORT_STRING:
391
392Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
393bool(false)
394-- Iteration 18 --
395Flag = default:
396
397Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
398bool(false)
399Flag = SORT_REGULAR:
400
401Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
402bool(false)
403Flag = SORT_NUMERIC:
404
405Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
406bool(false)
407Flag = SORT_STRING:
408
409Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
410bool(false)
411-- Iteration 19 --
412Flag = default:
413
414Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
415bool(false)
416Flag = SORT_REGULAR:
417
418Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
419bool(false)
420Flag = SORT_NUMERIC:
421
422Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
423bool(false)
424Flag = SORT_STRING:
425
426Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
427bool(false)
428-- Iteration 20 --
429Flag = default:
430
431Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
432bool(false)
433Flag = SORT_REGULAR:
434
435Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
436bool(false)
437Flag = SORT_NUMERIC:
438
439Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
440bool(false)
441Flag = SORT_STRING:
442
443Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
444bool(false)
445-- Iteration 21 --
446Flag = default:
447
448Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
449bool(false)
450Flag = SORT_REGULAR:
451
452Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
453bool(false)
454Flag = SORT_NUMERIC:
455
456Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
457bool(false)
458Flag = SORT_STRING:
459
460Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
461bool(false)
462-- Iteration 22 --
463Flag = default:
464
465Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
466bool(false)
467Flag = SORT_REGULAR:
468
469Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
470bool(false)
471Flag = SORT_NUMERIC:
472
473Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
474bool(false)
475Flag = SORT_STRING:
476
477Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
478bool(false)
479-- Iteration 23 --
480Flag = default:
481
482Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
483bool(false)
484Flag = SORT_REGULAR:
485
486Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
487bool(false)
488Flag = SORT_NUMERIC:
489
490Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
491bool(false)
492Flag = SORT_STRING:
493
494Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
495bool(false)
496-- Iteration 24 --
497Flag = default:
498
499Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
500bool(false)
501Flag = SORT_REGULAR:
502
503Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
504bool(false)
505Flag = SORT_NUMERIC:
506
507Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
508bool(false)
509Flag = SORT_STRING:
510
511Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
512bool(false)
513Done
514