1--TEST--
2Test rsort() function : object functionality
3--FILE--
4<?php
5/*
6 * Test basic functionality of rsort() with objects
7 */
8
9echo "*** Testing rsort() : object functionality ***\n";
10
11// class declaration for integer objects
12class for_integer_rsort
13{
14    public $class_value;
15    // initializing object member value
16    function __construct($value){
17        $this->class_value = $value;
18    }
19
20}
21
22// class declaration for string objects
23class for_string_rsort
24{
25    public $class_value;
26    // initializing object member value
27    function __construct($value){
28        $this->class_value = $value;
29    }
30
31    // return string value
32    function __tostring() {
33        return (string)$this->value;
34    }
35
36}
37
38// array of integer objects
39$unsorted_int_obj = array(
40  new for_integer_rsort(11), new for_integer_rsort(66),
41  new for_integer_rsort(23), new for_integer_rsort(-5),
42  new for_integer_rsort(0.001), new for_integer_rsort(0)
43);
44
45// array of string objects
46$unsorted_str_obj = array (
47  new for_string_rsort("axx"), new for_string_rsort("t"),
48  new for_string_rsort("w"), new for_string_rsort("py"),
49  new for_string_rsort("apple"), new for_string_rsort("Orange"),
50  new for_string_rsort("Lemon"), new for_string_rsort("aPPle")
51);
52
53
54echo "\n-- Sort flag = default --\n";
55
56// testing rsort() function by supplying integer object array, flag value is default
57$temp_array = $unsorted_int_obj;
58var_dump(rsort($temp_array) );
59var_dump($temp_array);
60
61// testing rsort() function by supplying string object array, flag value is default
62$temp_array = $unsorted_str_obj;
63var_dump(rsort($temp_array) );
64var_dump($temp_array);
65
66echo "\n-- Sort flag = SORT_REGULAR --\n";
67// testing rsort() function by supplying integer object array, flag value = SORT_REGULAR
68$temp_array = $unsorted_int_obj;
69var_dump(rsort($temp_array, SORT_REGULAR) );
70var_dump($temp_array);
71
72// testing rsort() function by supplying string object array, flag value = SORT_REGULAR
73$temp_array = $unsorted_str_obj;
74var_dump(rsort($temp_array, SORT_REGULAR) );
75var_dump($temp_array);
76
77echo "Done";
78?>
79--EXPECTF--
80*** Testing rsort() : object functionality ***
81
82-- Sort flag = default --
83bool(true)
84array(6) {
85  [0]=>
86  object(for_integer_rsort)#%d (1) {
87    ["class_value"]=>
88    int(66)
89  }
90  [1]=>
91  object(for_integer_rsort)#%d (1) {
92    ["class_value"]=>
93    int(23)
94  }
95  [2]=>
96  object(for_integer_rsort)#%d (1) {
97    ["class_value"]=>
98    int(11)
99  }
100  [3]=>
101  object(for_integer_rsort)#%d (1) {
102    ["class_value"]=>
103    float(0.001)
104  }
105  [4]=>
106  object(for_integer_rsort)#%d (1) {
107    ["class_value"]=>
108    int(0)
109  }
110  [5]=>
111  object(for_integer_rsort)#%d (1) {
112    ["class_value"]=>
113    int(-5)
114  }
115}
116bool(true)
117array(8) {
118  [0]=>
119  object(for_string_rsort)#%d (1) {
120    ["class_value"]=>
121    string(1) "w"
122  }
123  [1]=>
124  object(for_string_rsort)#%d (1) {
125    ["class_value"]=>
126    string(1) "t"
127  }
128  [2]=>
129  object(for_string_rsort)#%d (1) {
130    ["class_value"]=>
131    string(2) "py"
132  }
133  [3]=>
134  object(for_string_rsort)#%d (1) {
135    ["class_value"]=>
136    string(3) "axx"
137  }
138  [4]=>
139  object(for_string_rsort)#%d (1) {
140    ["class_value"]=>
141    string(5) "apple"
142  }
143  [5]=>
144  object(for_string_rsort)#%d (1) {
145    ["class_value"]=>
146    string(5) "aPPle"
147  }
148  [6]=>
149  object(for_string_rsort)#%d (1) {
150    ["class_value"]=>
151    string(6) "Orange"
152  }
153  [7]=>
154  object(for_string_rsort)#%d (1) {
155    ["class_value"]=>
156    string(5) "Lemon"
157  }
158}
159
160-- Sort flag = SORT_REGULAR --
161bool(true)
162array(6) {
163  [0]=>
164  object(for_integer_rsort)#%d (1) {
165    ["class_value"]=>
166    int(66)
167  }
168  [1]=>
169  object(for_integer_rsort)#%d (1) {
170    ["class_value"]=>
171    int(23)
172  }
173  [2]=>
174  object(for_integer_rsort)#%d (1) {
175    ["class_value"]=>
176    int(11)
177  }
178  [3]=>
179  object(for_integer_rsort)#%d (1) {
180    ["class_value"]=>
181    float(0.001)
182  }
183  [4]=>
184  object(for_integer_rsort)#%d (1) {
185    ["class_value"]=>
186    int(0)
187  }
188  [5]=>
189  object(for_integer_rsort)#%d (1) {
190    ["class_value"]=>
191    int(-5)
192  }
193}
194bool(true)
195array(8) {
196  [0]=>
197  object(for_string_rsort)#%d (1) {
198    ["class_value"]=>
199    string(1) "w"
200  }
201  [1]=>
202  object(for_string_rsort)#%d (1) {
203    ["class_value"]=>
204    string(1) "t"
205  }
206  [2]=>
207  object(for_string_rsort)#%d (1) {
208    ["class_value"]=>
209    string(2) "py"
210  }
211  [3]=>
212  object(for_string_rsort)#%d (1) {
213    ["class_value"]=>
214    string(3) "axx"
215  }
216  [4]=>
217  object(for_string_rsort)#%d (1) {
218    ["class_value"]=>
219    string(5) "apple"
220  }
221  [5]=>
222  object(for_string_rsort)#%d (1) {
223    ["class_value"]=>
224    string(5) "aPPle"
225  }
226  [6]=>
227  object(for_string_rsort)#%d (1) {
228    ["class_value"]=>
229    string(6) "Orange"
230  }
231  [7]=>
232  object(for_string_rsort)#%d (1) {
233    ["class_value"]=>
234    string(5) "Lemon"
235  }
236}
237Done
238