1--TEST-- 2Test 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 14echo "*** Testing uasort() : Unexpected values in place of comparison function ***\n"; 15 16// Class definition for object variable 17class 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; 29unset ($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' 89for($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 95fclose($fp); 96echo "Done" 97?> 98--EXPECTF-- 99*** Testing uasort() : Unexpected values in place of comparison function *** 100-- Iteration 1 -- 101 102Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 103NULL 104-- Iteration 2 -- 105 106Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 107NULL 108-- Iteration 3 -- 109 110Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 111NULL 112-- Iteration 4 -- 113 114Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 115NULL 116-- Iteration 5 -- 117 118Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 119NULL 120-- Iteration 6 -- 121 122Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 123NULL 124-- Iteration 7 -- 125 126Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 127NULL 128-- Iteration 8 -- 129 130Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 131NULL 132-- Iteration 9 -- 133 134Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 135NULL 136-- Iteration 10 -- 137 138Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 139NULL 140-- Iteration 11 -- 141 142Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 143NULL 144-- Iteration 12 -- 145 146Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 147NULL 148-- Iteration 13 -- 149 150Warning: 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 151NULL 152-- Iteration 14 -- 153 154Warning: 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 155NULL 156-- Iteration 15 -- 157 158Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 159NULL 160-- Iteration 16 -- 161 162Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 163NULL 164-- Iteration 17 -- 165 166Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 167NULL 168-- Iteration 18 -- 169 170Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 171NULL 172-- Iteration 19 -- 173 174Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 175NULL 176-- Iteration 20 -- 177 178Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 179NULL 180-- Iteration 21 -- 181 182Warning: uasort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d 183NULL 184-- Iteration 22 -- 185 186Warning: uasort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d 187NULL 188-- Iteration 23 -- 189 190Warning: uasort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d 191NULL 192-- Iteration 24 -- 193 194Warning: uasort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d 195NULL 196-- Iteration 25 -- 197 198Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 199NULL 200-- Iteration 26 -- 201 202Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 203NULL 204-- Iteration 27 -- 205 206Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 207NULL 208-- Iteration 28 -- 209 210Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 211NULL 212Done 213