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