1--TEST-- 2Test uksort() function : usage variation 3--FILE-- 4<?php 5/* Prototype : bool uksort(array array_arg, string cmp_function) 6 * Description: Sort an array by keys using a user-defined comparison function 7 * Source code: ext/standard/array.c 8 * Alias to functions: 9 */ 10 11echo "*** Testing uksort() : usage variation ***\n"; 12 13// Initialise function arguments not being substituted (if any) 14$array_arg = array(1, 2); 15 16//get an unset variable 17$unset_var = 10; 18unset ($unset_var); 19 20// define some classes 21class classWithToString 22{ 23 public function __toString() { 24 return "Class A object"; 25 } 26} 27 28class classWithoutToString 29{ 30} 31 32// heredoc string 33$heredoc = <<<EOT 34hello world 35EOT; 36 37// add arrays 38$index_array = array (1, 2, 3); 39$assoc_array = array ('one' => 1, 'two' => 2); 40 41//array of values to iterate over 42$inputs = array( 43 44 // int data 45 'int 0' => 0, 46 'int 1' => 1, 47 'int 12345' => 12345, 48 'int -12345' => -2345, 49 50 // float data 51 'float 10.5' => 10.5, 52 'float -10.5' => -10.5, 53 'float 12.3456789000e10' => 12.3456789000e10, 54 'float -12.3456789000e10' => -12.3456789000e10, 55 'float .5' => .5, 56 57 // array data 58 'empty array' => array(), 59 'int indexed array' => $index_array, 60 'associative array' => $assoc_array, 61 'nested arrays' => array('foo', $index_array, $assoc_array), 62 63 // null data 64 'uppercase NULL' => NULL, 65 'lowercase null' => null, 66 67 // boolean data 68 'lowercase true' => true, 69 'lowercase false' =>false, 70 'uppercase TRUE' =>TRUE, 71 'uppercase FALSE' =>FALSE, 72 73 // empty data 74 'empty string DQ' => "", 75 'empty string SQ' => '', 76 77 // object data 78 'instance of classWithToString' => new classWithToString(), 79 'instance of classWithoutToString' => new classWithoutToString(), 80 81 // undefined data 82 'undefined var' => @$undefined_var, 83 84 // unset data 85 'unset var' => @$unset_var, 86); 87 88// loop through each element of the array for cmp_function 89 90foreach($inputs as $key =>$value) { 91 echo "\n--$key--\n"; 92 var_dump( uksort($array_arg, $value) ); 93}; 94 95?> 96===DONE=== 97--EXPECTF-- 98*** Testing uksort() : usage variation *** 99 100--int 0-- 101 102Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 103NULL 104 105--int 1-- 106 107Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 108NULL 109 110--int 12345-- 111 112Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 113NULL 114 115--int -12345-- 116 117Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 118NULL 119 120--float 10.5-- 121 122Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 123NULL 124 125--float -10.5-- 126 127Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 128NULL 129 130--float 12.3456789000e10-- 131 132Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 133NULL 134 135--float -12.3456789000e10-- 136 137Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 138NULL 139 140--float .5-- 141 142Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 143NULL 144 145--empty array-- 146 147Warning: uksort() expects parameter 2 to be a valid callback, array must have exactly two members in %suksort_variation2.php on line %d 148NULL 149 150--int indexed array-- 151 152Warning: uksort() expects parameter 2 to be a valid callback, array must have exactly two members in %suksort_variation2.php on line %d 153NULL 154 155--associative array-- 156 157Warning: uksort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %suksort_variation2.php on line %d 158NULL 159 160--nested arrays-- 161 162Warning: uksort() expects parameter 2 to be a valid callback, array must have exactly two members in %suksort_variation2.php on line %d 163NULL 164 165--uppercase NULL-- 166 167Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 168NULL 169 170--lowercase null-- 171 172Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 173NULL 174 175--lowercase true-- 176 177Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 178NULL 179 180--lowercase false-- 181 182Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 183NULL 184 185--uppercase TRUE-- 186 187Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 188NULL 189 190--uppercase FALSE-- 191 192Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 193NULL 194 195--empty string DQ-- 196 197Warning: uksort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %suksort_variation2.php on line %d 198NULL 199 200--empty string SQ-- 201 202Warning: uksort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %suksort_variation2.php on line %d 203NULL 204 205--instance of classWithToString-- 206 207Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 208NULL 209 210--instance of classWithoutToString-- 211 212Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 213NULL 214 215--undefined var-- 216 217Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 218NULL 219 220--unset var-- 221 222Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d 223NULL 224===DONE=== 225