Return to krsort_variation2.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test krsort() function : usage variations - unexpected values for 'sort_flags' argument 3: --FILE-- 4: <?php 5: /* Prototype : bool krsort(array &array_arg [, int sort_flags]) 6: * Description: Sort an array by key in reverse order, maintaining key to data correlation 7: * Source code: ext/standard/array.c 8: */ 9: 10: /* 11: * Testing krsort() by providing different unexpected values for flag argument 12: */ 13: 14: echo "*** Testing krsort() : usage variations ***\n"; 15: 16: //get an unset variable 17: $unset_var = 10; 18: unset ($unset_var); 19: 20: // resource variable 21: $fp = fopen(__FILE__, "r"); 22: 23: // an array for checking unexpected behavior 24: $unsorted_values = array(10 => 10, 2 => 2, 45 => 45); 25: 26: //array of unexpected values to iterate over 27: $unexpected_values = array ( 28: 29: // int data 30: /*1*/ -2345, 31: 32: // float data 33: /*2*/ 10.5, 34: -10.5, 35: 10.5e2, 36: 10.6E-2, 37: .5, 38: 39: // null data 40: /*7*/ NULL, 41: null, 42: 43: // boolean data 44: /*9*/ true, 45: false, 46: TRUE, 47: FALSE, 48: 49: // empty data 50: /*13*/ "", 51: '', 52: 53: // string data 54: /*15*/ "string", 55: 'string', 56: 57: // object data 58: /*16*/ new stdclass(), 59: 60: // undefined data 61: /*17*/ @undefined_var, 62: 63: // unset data 64: /*18*/ @unset_var, 65: 66: // resource variable 67: /*19*/ $fp 68: 69: ); 70: 71: // loop though each element of the array and check the working of krsort() 72: // when 'sort_flags' arugment is supplied with different values 73: echo "\n-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --\n"; 74: 75: $counter = 1; 76: for($index = 0; $index < count($unexpected_values); $index ++) { 77: echo "-- Iteration $counter --\n"; 78: $value = $unexpected_values [$index]; 79: $temp_array = $unsorted_values; 80: var_dump( krsort($temp_array, $value) ); 81: var_dump($temp_array); 82: $counter++; 83: } 84: 85: echo "Done"; 86: ?> 87: --EXPECTF-- 88: *** Testing krsort() : usage variations *** 89: 90: -- Testing krsort() by supplying different unexpected values for 'sort_flags' argument -- 91: -- Iteration 1 -- 92: bool(true) 93: array(3) { 94: [45]=> 95: int(45) 96: [10]=> 97: int(10) 98: [2]=> 99: int(2) 100: } 101: -- Iteration 2 -- 102: bool(true) 103: array(3) { 104: [45]=> 105: int(45) 106: [2]=> 107: int(2) 1.1.1.2 ! misho 108: [10]=> ! 109: int(10) 1.1 misho 110: } 111: -- Iteration 3 -- 112: bool(true) 113: array(3) { 114: [45]=> 115: int(45) 116: [10]=> 117: int(10) 118: [2]=> 119: int(2) 120: } 121: -- Iteration 4 -- 122: bool(true) 123: array(3) { 124: [45]=> 125: int(45) 126: [10]=> 127: int(10) 128: [2]=> 129: int(2) 130: } 131: -- Iteration 5 -- 132: bool(true) 133: array(3) { 134: [45]=> 135: int(45) 136: [10]=> 137: int(10) 138: [2]=> 139: int(2) 140: } 141: -- Iteration 6 -- 142: bool(true) 143: array(3) { 144: [45]=> 145: int(45) 146: [10]=> 147: int(10) 148: [2]=> 149: int(2) 150: } 151: -- Iteration 7 -- 152: bool(true) 153: array(3) { 154: [45]=> 155: int(45) 156: [10]=> 157: int(10) 158: [2]=> 159: int(2) 160: } 161: -- Iteration 8 -- 162: bool(true) 163: array(3) { 164: [45]=> 165: int(45) 166: [10]=> 167: int(10) 168: [2]=> 169: int(2) 170: } 171: -- Iteration 9 -- 172: bool(true) 173: array(3) { 174: [45]=> 175: int(45) 176: [10]=> 177: int(10) 178: [2]=> 179: int(2) 180: } 181: -- Iteration 10 -- 182: bool(true) 183: array(3) { 184: [45]=> 185: int(45) 186: [10]=> 187: int(10) 188: [2]=> 189: int(2) 190: } 191: -- Iteration 11 -- 192: bool(true) 193: array(3) { 194: [45]=> 195: int(45) 196: [10]=> 197: int(10) 198: [2]=> 199: int(2) 200: } 201: -- Iteration 12 -- 202: bool(true) 203: array(3) { 204: [45]=> 205: int(45) 206: [10]=> 207: int(10) 208: [2]=> 209: int(2) 210: } 211: -- Iteration 13 -- 212: 213: Warning: krsort() expects parameter 2 to be long, string given in %s on line %d 214: bool(false) 215: array(3) { 216: [10]=> 217: int(10) 218: [2]=> 219: int(2) 220: [45]=> 221: int(45) 222: } 223: -- Iteration 14 -- 224: 225: Warning: krsort() expects parameter 2 to be long, string given in %s on line %d 226: bool(false) 227: array(3) { 228: [10]=> 229: int(10) 230: [2]=> 231: int(2) 232: [45]=> 233: int(45) 234: } 235: -- Iteration 15 -- 236: 237: Warning: krsort() expects parameter 2 to be long, string given in %s on line %d 238: bool(false) 239: array(3) { 240: [10]=> 241: int(10) 242: [2]=> 243: int(2) 244: [45]=> 245: int(45) 246: } 247: -- Iteration 16 -- 248: 249: Warning: krsort() expects parameter 2 to be long, string given in %s on line %d 250: bool(false) 251: array(3) { 252: [10]=> 253: int(10) 254: [2]=> 255: int(2) 256: [45]=> 257: int(45) 258: } 259: -- Iteration 17 -- 260: 261: Warning: krsort() expects parameter 2 to be long, object given in %s on line %d 262: bool(false) 263: array(3) { 264: [10]=> 265: int(10) 266: [2]=> 267: int(2) 268: [45]=> 269: int(45) 270: } 271: -- Iteration 18 -- 272: 273: Warning: krsort() expects parameter 2 to be long, string given in %s on line %d 274: bool(false) 275: array(3) { 276: [10]=> 277: int(10) 278: [2]=> 279: int(2) 280: [45]=> 281: int(45) 282: } 283: -- Iteration 19 -- 284: 285: Warning: krsort() expects parameter 2 to be long, string given in %s on line %d 286: bool(false) 287: array(3) { 288: [10]=> 289: int(10) 290: [2]=> 291: int(2) 292: [45]=> 293: int(45) 294: } 295: -- Iteration 20 -- 296: 297: Warning: krsort() expects parameter 2 to be long, resource given in %s on line %d 298: bool(false) 299: array(3) { 300: [10]=> 301: int(10) 302: [2]=> 303: int(2) 304: [45]=> 305: int(45) 306: } 307: Done