1--TEST-- 2Test sort() function : usage variations - unexpected values for 'array_arg' argument 3--FILE-- 4<?php 5/* Prototype : bool sort(array &array_arg [, int $sort_flags]) 6 * Description: Sort an array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * testing sort() by providing different unexpected values for array argument 12 * with following flag values. 13 * 1. flag value as defualt 14 * 2. SORT_REGULAR - compare items normally 15 * 3. SORT_NUMERIC - compare items numerically 16 * 4. SORT_STRING - compare items as strings 17*/ 18 19echo "*** Testing sort() : usage variations ***\n"; 20 21//get an unset variable 22$unset_var = 10; 23unset ($unset_var); 24 25// resource variable 26$fp = fopen(__FILE__, "r"); 27 28//array of values to iterate over 29$unexpected_values = array ( 30 31 // int data 32/*1*/ 0, 33 1, 34 12345, 35 -2345, 36 37 // float data 38/*5*/ 10.5, 39 -10.5, 40 10.5e3, 41 10.6E-2, 42 .5, 43 44 // null data 45/*10*/ NULL, 46 null, 47 48 // boolean data 49/*12*/ true, 50 false, 51 TRUE, 52 FALSE, 53 54 // empty data 55/*16*/ "", 56 '', 57 58 // string data 59/*18*/ "string", 60 'string', 61 62 // object data 63/*20*/ new stdclass(), 64 65 // undefined data 66/*21*/ @undefined_var, 67 68 // unset data 69/*22*/ @unset_var, 70 71 // resource variable 72/*23*/ $fp 73); 74 75// loop though each element of the array and check the working of sort() 76// when $array argument is supplied with different values from $unexpected_values 77echo "\n-- Testing sort() by supplying different unexpected values for 'array' argument --\n"; 78echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; 79 80$counter = 1; 81for($index = 0; $index < count($unexpected_values); $index ++) { 82 echo "-- Iteration $counter --\n"; 83 $value = $unexpected_values [$index]; 84 var_dump( sort($value) ); // expecting : bool(false) 85 var_dump( sort($value, SORT_REGULAR) ); // expecting : bool(false) 86 var_dump( sort($value, SORT_NUMERIC) ); // expecting : bool(false) 87 var_dump( sort($value, SORT_STRING) ); // expecting : bool(false) 88 $counter++; 89} 90 91echo "Done"; 92?> 93--EXPECTF-- 94*** Testing sort() : usage variations *** 95 96-- Testing sort() by supplying different unexpected values for 'array' argument -- 97 98-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- 99-- Iteration 1 -- 100 101Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 102bool(false) 103 104Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 105bool(false) 106 107Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 108bool(false) 109 110Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 111bool(false) 112-- Iteration 2 -- 113 114Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 115bool(false) 116 117Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 118bool(false) 119 120Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 121bool(false) 122 123Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 124bool(false) 125-- Iteration 3 -- 126 127Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 128bool(false) 129 130Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 131bool(false) 132 133Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 134bool(false) 135 136Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 137bool(false) 138-- Iteration 4 -- 139 140Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 141bool(false) 142 143Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 144bool(false) 145 146Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 147bool(false) 148 149Warning: sort() expects parameter 1 to be array, integer given in %s on line %d 150bool(false) 151-- Iteration 5 -- 152 153Warning: sort() expects parameter 1 to be array, double given in %s on line %d 154bool(false) 155 156Warning: sort() expects parameter 1 to be array, double given in %s on line %d 157bool(false) 158 159Warning: sort() expects parameter 1 to be array, double given in %s on line %d 160bool(false) 161 162Warning: sort() expects parameter 1 to be array, double given in %s on line %d 163bool(false) 164-- Iteration 6 -- 165 166Warning: sort() expects parameter 1 to be array, double given in %s on line %d 167bool(false) 168 169Warning: sort() expects parameter 1 to be array, double given in %s on line %d 170bool(false) 171 172Warning: sort() expects parameter 1 to be array, double given in %s on line %d 173bool(false) 174 175Warning: sort() expects parameter 1 to be array, double given in %s on line %d 176bool(false) 177-- Iteration 7 -- 178 179Warning: sort() expects parameter 1 to be array, double given in %s on line %d 180bool(false) 181 182Warning: sort() expects parameter 1 to be array, double given in %s on line %d 183bool(false) 184 185Warning: sort() expects parameter 1 to be array, double given in %s on line %d 186bool(false) 187 188Warning: sort() expects parameter 1 to be array, double given in %s on line %d 189bool(false) 190-- Iteration 8 -- 191 192Warning: sort() expects parameter 1 to be array, double given in %s on line %d 193bool(false) 194 195Warning: sort() expects parameter 1 to be array, double given in %s on line %d 196bool(false) 197 198Warning: sort() expects parameter 1 to be array, double given in %s on line %d 199bool(false) 200 201Warning: sort() expects parameter 1 to be array, double given in %s on line %d 202bool(false) 203-- Iteration 9 -- 204 205Warning: sort() expects parameter 1 to be array, double given in %s on line %d 206bool(false) 207 208Warning: sort() expects parameter 1 to be array, double given in %s on line %d 209bool(false) 210 211Warning: sort() expects parameter 1 to be array, double given in %s on line %d 212bool(false) 213 214Warning: sort() expects parameter 1 to be array, double given in %s on line %d 215bool(false) 216-- Iteration 10 -- 217 218Warning: sort() expects parameter 1 to be array, null given in %s on line %d 219bool(false) 220 221Warning: sort() expects parameter 1 to be array, null given in %s on line %d 222bool(false) 223 224Warning: sort() expects parameter 1 to be array, null given in %s on line %d 225bool(false) 226 227Warning: sort() expects parameter 1 to be array, null given in %s on line %d 228bool(false) 229-- Iteration 11 -- 230 231Warning: sort() expects parameter 1 to be array, null given in %s on line %d 232bool(false) 233 234Warning: sort() expects parameter 1 to be array, null given in %s on line %d 235bool(false) 236 237Warning: sort() expects parameter 1 to be array, null given in %s on line %d 238bool(false) 239 240Warning: sort() expects parameter 1 to be array, null given in %s on line %d 241bool(false) 242-- Iteration 12 -- 243 244Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 245bool(false) 246 247Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 248bool(false) 249 250Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 251bool(false) 252 253Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 254bool(false) 255-- Iteration 13 -- 256 257Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 258bool(false) 259 260Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 261bool(false) 262 263Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 264bool(false) 265 266Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 267bool(false) 268-- Iteration 14 -- 269 270Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 271bool(false) 272 273Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 274bool(false) 275 276Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 277bool(false) 278 279Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 280bool(false) 281-- Iteration 15 -- 282 283Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 284bool(false) 285 286Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 287bool(false) 288 289Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 290bool(false) 291 292Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d 293bool(false) 294-- Iteration 16 -- 295 296Warning: sort() expects parameter 1 to be array, string given in %s on line %d 297bool(false) 298 299Warning: sort() expects parameter 1 to be array, string given in %s on line %d 300bool(false) 301 302Warning: sort() expects parameter 1 to be array, string given in %s on line %d 303bool(false) 304 305Warning: sort() expects parameter 1 to be array, string given in %s on line %d 306bool(false) 307-- Iteration 17 -- 308 309Warning: sort() expects parameter 1 to be array, string given in %s on line %d 310bool(false) 311 312Warning: sort() expects parameter 1 to be array, string given in %s on line %d 313bool(false) 314 315Warning: sort() expects parameter 1 to be array, string given in %s on line %d 316bool(false) 317 318Warning: sort() expects parameter 1 to be array, string given in %s on line %d 319bool(false) 320-- Iteration 18 -- 321 322Warning: sort() expects parameter 1 to be array, string given in %s on line %d 323bool(false) 324 325Warning: sort() expects parameter 1 to be array, string given in %s on line %d 326bool(false) 327 328Warning: sort() expects parameter 1 to be array, string given in %s on line %d 329bool(false) 330 331Warning: sort() expects parameter 1 to be array, string given in %s on line %d 332bool(false) 333-- Iteration 19 -- 334 335Warning: sort() expects parameter 1 to be array, string given in %s on line %d 336bool(false) 337 338Warning: sort() expects parameter 1 to be array, string given in %s on line %d 339bool(false) 340 341Warning: sort() expects parameter 1 to be array, string given in %s on line %d 342bool(false) 343 344Warning: sort() expects parameter 1 to be array, string given in %s on line %d 345bool(false) 346-- Iteration 20 -- 347 348Warning: sort() expects parameter 1 to be array, object given in %s on line %d 349bool(false) 350 351Warning: sort() expects parameter 1 to be array, object given in %s on line %d 352bool(false) 353 354Warning: sort() expects parameter 1 to be array, object given in %s on line %d 355bool(false) 356 357Warning: sort() expects parameter 1 to be array, object given in %s on line %d 358bool(false) 359-- Iteration 21 -- 360 361Warning: sort() expects parameter 1 to be array, string given in %s on line %d 362bool(false) 363 364Warning: sort() expects parameter 1 to be array, string given in %s on line %d 365bool(false) 366 367Warning: sort() expects parameter 1 to be array, string given in %s on line %d 368bool(false) 369 370Warning: sort() expects parameter 1 to be array, string given in %s on line %d 371bool(false) 372-- Iteration 22 -- 373 374Warning: sort() expects parameter 1 to be array, string given in %s on line %d 375bool(false) 376 377Warning: sort() expects parameter 1 to be array, string given in %s on line %d 378bool(false) 379 380Warning: sort() expects parameter 1 to be array, string given in %s on line %d 381bool(false) 382 383Warning: sort() expects parameter 1 to be array, string given in %s on line %d 384bool(false) 385-- Iteration 23 -- 386 387Warning: sort() expects parameter 1 to be array, resource given in %s on line %d 388bool(false) 389 390Warning: sort() expects parameter 1 to be array, resource given in %s on line %d 391bool(false) 392 393Warning: sort() expects parameter 1 to be array, resource given in %s on line %d 394bool(false) 395 396Warning: sort() expects parameter 1 to be array, resource given in %s on line %d 397bool(false) 398Done 399