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