Return to uasort_variation2.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test uasort() function : usage variations - unexpected values for 'cmp_function' argument 3: --FILE-- 4: <?php 5: /* Prototype : bool uasort(array $array_arg, string $cmp_function) 6: * Description: Sort an array with a user-defined comparison function and maintain index association 7: * Source code: ext/standard/array.c 8: */ 9: 10: /* 11: * Testing uasort() function with different scalar and nonscalar values in place of 'cmp_function' 12: */ 13: 14: echo "*** Testing uasort() : Unexpected values in place of comparison function ***\n"; 15: 16: // Class definition for object variable 17: class MyClass 18: { 19: public function __toString() 20: { 21: return 'object'; 22: } 23: } 24: 25: $array_arg = array(0 => 1, 1 => -1, 2 => 3, 3 => 10, 4 => 4, 5 => 2, 6 => 8, 7 => 5); 26: 27: // Get an unset variable 28: $unset_var = 10; 29: unset ($unset_var); 30: 31: // Get resource variable 32: $fp = fopen(__FILE__,'r'); 33: 34: // different values for 'cmp_function' 35: $cmp_values = array( 36: 37: // int data 38: /*1*/ 0, 39: 1, 40: 12345, 41: -2345, 42: 43: // float data 44: /*5*/ 10.5, 45: -10.5, 46: 10.1234567e8, 47: 10.7654321E-8, 48: .5, 49: 50: // array data 51: /*10*/ array(), 52: array(0), 53: array(1), 54: array(1, 2), 55: array('color' => 'red', 'item' => 'pen'), 56: 57: // null data 58: /*15*/ NULL, 59: null, 60: 61: // boolean data 62: /*17*/ true, 63: false, 64: TRUE, 65: FALSE, 66: 67: // empty data 68: /*21*/ "", 69: '', 70: 71: // string data 72: "string", 73: 'string', 74: 75: // object data 76: /*25*/ new MyClass(), 77: 78: // resource data 79: $fp, 80: 81: // undefined data 82: @$undefined_var, 83: 84: // unset data 85: /*28*/ @$unset_var, 86: ); 87: 88: // loop through each element of the cmp_values for 'cmp_function' 89: for($count = 0; $count < count($cmp_values); $count++) { 90: echo "-- Iteration ".($count + 1)." --\n"; 91: var_dump( uasort($array_arg, $cmp_values[$count]) ); 92: }; 93: 94: //closing resource 95: fclose($fp); 96: echo "Done" 97: ?> 98: --EXPECTF-- 99: *** Testing uasort() : Unexpected values in place of comparison function *** 100: -- Iteration 1 -- 101: 102: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 103: NULL 104: -- Iteration 2 -- 105: 106: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 107: NULL 108: -- Iteration 3 -- 109: 110: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 111: NULL 112: -- Iteration 4 -- 113: 114: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 115: NULL 116: -- Iteration 5 -- 117: 118: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 119: NULL 120: -- Iteration 6 -- 121: 122: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 123: NULL 124: -- Iteration 7 -- 125: 126: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 127: NULL 128: -- Iteration 8 -- 129: 130: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 131: NULL 132: -- Iteration 9 -- 133: 134: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 135: NULL 136: -- Iteration 10 -- 137: 138: Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 139: NULL 140: -- Iteration 11 -- 141: 142: Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 143: NULL 144: -- Iteration 12 -- 145: 146: Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 147: NULL 148: -- Iteration 13 -- 149: 150: Warning: uasort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d 151: NULL 152: -- Iteration 14 -- 153: 154: Warning: uasort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d 155: NULL 156: -- Iteration 15 -- 157: 158: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 159: NULL 160: -- Iteration 16 -- 161: 162: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 163: NULL 164: -- Iteration 17 -- 165: 166: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 167: NULL 168: -- Iteration 18 -- 169: 170: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 171: NULL 172: -- Iteration 19 -- 173: 174: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 175: NULL 176: -- Iteration 20 -- 177: 178: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 179: NULL 180: -- Iteration 21 -- 181: 182: Warning: uasort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d 183: NULL 184: -- Iteration 22 -- 185: 186: Warning: uasort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d 187: NULL 188: -- Iteration 23 -- 189: 190: Warning: uasort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d 191: NULL 192: -- Iteration 24 -- 193: 194: Warning: uasort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d 195: NULL 196: -- Iteration 25 -- 197: 198: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 199: NULL 200: -- Iteration 26 -- 201: 202: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 203: NULL 204: -- Iteration 27 -- 205: 206: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 207: NULL 208: -- Iteration 28 -- 209: 210: Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 211: NULL 212: Done