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