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