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