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