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