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