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