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
104--EXPECTF--
105*** Testing rsort() : variation ***
106-- Iteration 1 --
107Flag = default:
108
109Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
110bool(false)
111Flag = SORT_REGULAR:
112
113Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
114bool(false)
115Flag = SORT_NUMERIC:
116
117Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
118bool(false)
119Flag = SORT_STRING:
120
121Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
122bool(false)
123-- Iteration 2 --
124Flag = default:
125
126Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
127bool(false)
128Flag = SORT_REGULAR:
129
130Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
131bool(false)
132Flag = SORT_NUMERIC:
133
134Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
135bool(false)
136Flag = SORT_STRING:
137
138Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
139bool(false)
140-- Iteration 3 --
141Flag = default:
142
143Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
144bool(false)
145Flag = SORT_REGULAR:
146
147Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
148bool(false)
149Flag = SORT_NUMERIC:
150
151Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
152bool(false)
153Flag = SORT_STRING:
154
155Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
156bool(false)
157-- Iteration 4 --
158Flag = default:
159
160Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
161bool(false)
162Flag = SORT_REGULAR:
163
164Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
165bool(false)
166Flag = SORT_NUMERIC:
167
168Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
169bool(false)
170Flag = SORT_STRING:
171
172Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d
173bool(false)
174-- Iteration 5 --
175Flag = default:
176
177Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
178bool(false)
179Flag = SORT_REGULAR:
180
181Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
182bool(false)
183Flag = SORT_NUMERIC:
184
185Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
186bool(false)
187Flag = SORT_STRING:
188
189Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
190bool(false)
191-- Iteration 6 --
192Flag = default:
193
194Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
195bool(false)
196Flag = SORT_REGULAR:
197
198Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
199bool(false)
200Flag = SORT_NUMERIC:
201
202Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
203bool(false)
204Flag = SORT_STRING:
205
206Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
207bool(false)
208-- Iteration 7 --
209Flag = default:
210
211Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
212bool(false)
213Flag = SORT_REGULAR:
214
215Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
216bool(false)
217Flag = SORT_NUMERIC:
218
219Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
220bool(false)
221Flag = SORT_STRING:
222
223Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
224bool(false)
225-- Iteration 8 --
226Flag = default:
227
228Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
229bool(false)
230Flag = SORT_REGULAR:
231
232Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
233bool(false)
234Flag = SORT_NUMERIC:
235
236Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
237bool(false)
238Flag = SORT_STRING:
239
240Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
241bool(false)
242-- Iteration 9 --
243Flag = default:
244
245Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
246bool(false)
247Flag = SORT_REGULAR:
248
249Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
250bool(false)
251Flag = SORT_NUMERIC:
252
253Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
254bool(false)
255Flag = SORT_STRING:
256
257Warning: rsort() expects parameter 1 to be array, double given in %s on line %d
258bool(false)
259-- Iteration 10 --
260Flag = default:
261
262Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
263bool(false)
264Flag = SORT_REGULAR:
265
266Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
267bool(false)
268Flag = SORT_NUMERIC:
269
270Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
271bool(false)
272Flag = SORT_STRING:
273
274Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
275bool(false)
276-- Iteration 11 --
277Flag = default:
278
279Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
280bool(false)
281Flag = SORT_REGULAR:
282
283Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
284bool(false)
285Flag = SORT_NUMERIC:
286
287Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
288bool(false)
289Flag = SORT_STRING:
290
291Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
292bool(false)
293-- Iteration 12 --
294Flag = default:
295
296Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
297bool(false)
298Flag = SORT_REGULAR:
299
300Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
301bool(false)
302Flag = SORT_NUMERIC:
303
304Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
305bool(false)
306Flag = SORT_STRING:
307
308Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
309bool(false)
310-- Iteration 13 --
311Flag = default:
312
313Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
314bool(false)
315Flag = SORT_REGULAR:
316
317Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
318bool(false)
319Flag = SORT_NUMERIC:
320
321Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
322bool(false)
323Flag = SORT_STRING:
324
325Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
326bool(false)
327-- Iteration 14 --
328Flag = default:
329
330Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
331bool(false)
332Flag = SORT_REGULAR:
333
334Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
335bool(false)
336Flag = SORT_NUMERIC:
337
338Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
339bool(false)
340Flag = SORT_STRING:
341
342Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
343bool(false)
344-- Iteration 15 --
345Flag = default:
346
347Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
348bool(false)
349Flag = SORT_REGULAR:
350
351Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
352bool(false)
353Flag = SORT_NUMERIC:
354
355Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
356bool(false)
357Flag = SORT_STRING:
358
359Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d
360bool(false)
361-- Iteration 16 --
362Flag = default:
363
364Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
365bool(false)
366Flag = SORT_REGULAR:
367
368Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
369bool(false)
370Flag = SORT_NUMERIC:
371
372Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
373bool(false)
374Flag = SORT_STRING:
375
376Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
377bool(false)
378-- Iteration 17 --
379Flag = default:
380
381Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
382bool(false)
383Flag = SORT_REGULAR:
384
385Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
386bool(false)
387Flag = SORT_NUMERIC:
388
389Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
390bool(false)
391Flag = SORT_STRING:
392
393Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
394bool(false)
395-- Iteration 18 --
396Flag = default:
397
398Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
399bool(false)
400Flag = SORT_REGULAR:
401
402Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
403bool(false)
404Flag = SORT_NUMERIC:
405
406Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
407bool(false)
408Flag = SORT_STRING:
409
410Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
411bool(false)
412-- Iteration 19 --
413Flag = default:
414
415Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
416bool(false)
417Flag = SORT_REGULAR:
418
419Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
420bool(false)
421Flag = SORT_NUMERIC:
422
423Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
424bool(false)
425Flag = SORT_STRING:
426
427Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
428bool(false)
429-- Iteration 20 --
430Flag = default:
431
432Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
433bool(false)
434Flag = SORT_REGULAR:
435
436Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
437bool(false)
438Flag = SORT_NUMERIC:
439
440Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
441bool(false)
442Flag = SORT_STRING:
443
444Warning: rsort() expects parameter 1 to be array, string given in %s on line %d
445bool(false)
446-- Iteration 21 --
447Flag = default:
448
449Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
450bool(false)
451Flag = SORT_REGULAR:
452
453Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
454bool(false)
455Flag = SORT_NUMERIC:
456
457Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
458bool(false)
459Flag = SORT_STRING:
460
461Warning: rsort() expects parameter 1 to be array, object given in %s on line %d
462bool(false)
463-- Iteration 22 --
464Flag = default:
465
466Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
467bool(false)
468Flag = SORT_REGULAR:
469
470Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
471bool(false)
472Flag = SORT_NUMERIC:
473
474Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
475bool(false)
476Flag = SORT_STRING:
477
478Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
479bool(false)
480-- Iteration 23 --
481Flag = default:
482
483Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
484bool(false)
485Flag = SORT_REGULAR:
486
487Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
488bool(false)
489Flag = SORT_NUMERIC:
490
491Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
492bool(false)
493Flag = SORT_STRING:
494
495Warning: rsort() expects parameter 1 to be array, null given in %s on line %d
496bool(false)
497-- Iteration 24 --
498Flag = default:
499
500Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
501bool(false)
502Flag = SORT_REGULAR:
503
504Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
505bool(false)
506Flag = SORT_NUMERIC:
507
508Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
509bool(false)
510Flag = SORT_STRING:
511
512Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d
513bool(false)
514Done