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