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