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