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