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