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