1--TEST-- 2Test rsort() function : usage variations - Pass different data types as $sort_flags arg 3--SKIPIF-- 4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only"); 5--FILE-- 6<?php 7/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) 8 * Description: Sort an array in reverse order 9 * Source code: ext/standard/array.c 10 */ 11 12/* 13 * Pass different data types as $sort_flags argument to rsort() to test behaviour 14 * Where possible, 'SORT_NUMERIC' has been entered as a string value 15 */ 16 17echo "*** Testing rsort() : variation ***\n"; 18 19// Initialise function arguments not being substituted 20$array_arg = array (1, 5, 2, 3, 1); 21 22//get an unset variable 23$unset_var = 10; 24unset ($unset_var); 25 26// get a class 27class classA 28{ 29 public function __toString() { 30 return "SORT_NUMERIC"; 31 } 32} 33 34// heredoc string 35$heredoc = <<<EOT 36SORT_NUMERIC 37EOT; 38 39// get a resource variable 40$fp = fopen(__FILE__, "r"); 41 42// unexpected values to be passed to $sort_flags argument 43$inputs = array( 44 45 // int data 46/*1*/ 0, 47 1, 48 12345, 49 -2345, 50 51 // float data 52/*5*/ 10.5, 53 -10.5, 54 12.3456789000e10, 55 12.3456789000E-10, 56 .5, 57 58 // null data 59/*10*/ NULL, 60 null, 61 62 // boolean data 63/*12*/ true, 64 false, 65 TRUE, 66 FALSE, 67 68 // empty data 69/*16*/ "", 70 '', 71 72 // string data 73/*18*/ "SORT_NUMERIC", 74 'SORT_NUMERIC', 75 $heredoc, 76 77 // object data 78/*21*/ new classA(), 79 80 // undefined data 81/*22*/ @$undefined_var, 82 83 // unset data 84/*23*/ @$unset_var, 85 86 // resource variable 87/*24*/ $fp 88); 89 90// loop through each element of $inputs to check the behavior of rsort() 91$iterator = 1; 92foreach($inputs as $input) { 93 echo "\n-- Iteration $iterator --\n"; 94 95 //create temporary array in case rsort() works 96 $temp = $array_arg; 97 98 var_dump( rsort($temp, $input) ); 99 var_dump($temp); 100 $iterator++; 101 102 $temp = null; 103}; 104 105fclose($fp); 106 107echo "Done"; 108?> 109--EXPECTF-- 110*** Testing rsort() : variation *** 111 112-- Iteration 1 -- 113bool(true) 114array(5) { 115 [0]=> 116 int(5) 117 [1]=> 118 int(3) 119 [2]=> 120 int(2) 121 [3]=> 122 int(1) 123 [4]=> 124 int(1) 125} 126 127-- Iteration 2 -- 128bool(true) 129array(5) { 130 [0]=> 131 int(5) 132 [1]=> 133 int(3) 134 [2]=> 135 int(2) 136 [3]=> 137 int(1) 138 [4]=> 139 int(1) 140} 141 142-- Iteration 3 -- 143bool(true) 144array(5) { 145 [0]=> 146 int(5) 147 [1]=> 148 int(3) 149 [2]=> 150 int(2) 151 [3]=> 152 int(1) 153 [4]=> 154 int(1) 155} 156 157-- Iteration 4 -- 158bool(true) 159array(5) { 160 [0]=> 161 int(5) 162 [1]=> 163 int(3) 164 [2]=> 165 int(2) 166 [3]=> 167 int(1) 168 [4]=> 169 int(1) 170} 171 172-- Iteration 5 -- 173bool(true) 174array(5) { 175 [0]=> 176 int(5) 177 [1]=> 178 int(3) 179 [2]=> 180 int(2) 181 [3]=> 182 int(1) 183 [4]=> 184 int(1) 185} 186 187-- Iteration 6 -- 188bool(true) 189array(5) { 190 [0]=> 191 int(5) 192 [1]=> 193 int(3) 194 [2]=> 195 int(2) 196 [3]=> 197 int(1) 198 [4]=> 199 int(1) 200} 201 202-- Iteration 7 -- 203bool(true) 204array(5) { 205 [0]=> 206 int(5) 207 [1]=> 208 int(3) 209 [2]=> 210 int(2) 211 [3]=> 212 int(1) 213 [4]=> 214 int(1) 215} 216 217-- Iteration 8 -- 218bool(true) 219array(5) { 220 [0]=> 221 int(5) 222 [1]=> 223 int(3) 224 [2]=> 225 int(2) 226 [3]=> 227 int(1) 228 [4]=> 229 int(1) 230} 231 232-- Iteration 9 -- 233bool(true) 234array(5) { 235 [0]=> 236 int(5) 237 [1]=> 238 int(3) 239 [2]=> 240 int(2) 241 [3]=> 242 int(1) 243 [4]=> 244 int(1) 245} 246 247-- Iteration 10 -- 248bool(true) 249array(5) { 250 [0]=> 251 int(5) 252 [1]=> 253 int(3) 254 [2]=> 255 int(2) 256 [3]=> 257 int(1) 258 [4]=> 259 int(1) 260} 261 262-- Iteration 11 -- 263bool(true) 264array(5) { 265 [0]=> 266 int(5) 267 [1]=> 268 int(3) 269 [2]=> 270 int(2) 271 [3]=> 272 int(1) 273 [4]=> 274 int(1) 275} 276 277-- Iteration 12 -- 278bool(true) 279array(5) { 280 [0]=> 281 int(5) 282 [1]=> 283 int(3) 284 [2]=> 285 int(2) 286 [3]=> 287 int(1) 288 [4]=> 289 int(1) 290} 291 292-- Iteration 13 -- 293bool(true) 294array(5) { 295 [0]=> 296 int(5) 297 [1]=> 298 int(3) 299 [2]=> 300 int(2) 301 [3]=> 302 int(1) 303 [4]=> 304 int(1) 305} 306 307-- Iteration 14 -- 308bool(true) 309array(5) { 310 [0]=> 311 int(5) 312 [1]=> 313 int(3) 314 [2]=> 315 int(2) 316 [3]=> 317 int(1) 318 [4]=> 319 int(1) 320} 321 322-- Iteration 15 -- 323bool(true) 324array(5) { 325 [0]=> 326 int(5) 327 [1]=> 328 int(3) 329 [2]=> 330 int(2) 331 [3]=> 332 int(1) 333 [4]=> 334 int(1) 335} 336 337-- Iteration 16 -- 338 339Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 340bool(false) 341array(5) { 342 [0]=> 343 int(1) 344 [1]=> 345 int(5) 346 [2]=> 347 int(2) 348 [3]=> 349 int(3) 350 [4]=> 351 int(1) 352} 353 354-- Iteration 17 -- 355 356Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 357bool(false) 358array(5) { 359 [0]=> 360 int(1) 361 [1]=> 362 int(5) 363 [2]=> 364 int(2) 365 [3]=> 366 int(3) 367 [4]=> 368 int(1) 369} 370 371-- Iteration 18 -- 372 373Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 374bool(false) 375array(5) { 376 [0]=> 377 int(1) 378 [1]=> 379 int(5) 380 [2]=> 381 int(2) 382 [3]=> 383 int(3) 384 [4]=> 385 int(1) 386} 387 388-- Iteration 19 -- 389 390Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 391bool(false) 392array(5) { 393 [0]=> 394 int(1) 395 [1]=> 396 int(5) 397 [2]=> 398 int(2) 399 [3]=> 400 int(3) 401 [4]=> 402 int(1) 403} 404 405-- Iteration 20 -- 406 407Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 408bool(false) 409array(5) { 410 [0]=> 411 int(1) 412 [1]=> 413 int(5) 414 [2]=> 415 int(2) 416 [3]=> 417 int(3) 418 [4]=> 419 int(1) 420} 421 422-- Iteration 21 -- 423 424Warning: rsort() expects parameter 2 to be integer, object given in %s on line %d 425bool(false) 426array(5) { 427 [0]=> 428 int(1) 429 [1]=> 430 int(5) 431 [2]=> 432 int(2) 433 [3]=> 434 int(3) 435 [4]=> 436 int(1) 437} 438 439-- Iteration 22 -- 440bool(true) 441array(5) { 442 [0]=> 443 int(5) 444 [1]=> 445 int(3) 446 [2]=> 447 int(2) 448 [3]=> 449 int(1) 450 [4]=> 451 int(1) 452} 453 454-- Iteration 23 -- 455bool(true) 456array(5) { 457 [0]=> 458 int(5) 459 [1]=> 460 int(3) 461 [2]=> 462 int(2) 463 [3]=> 464 int(1) 465 [4]=> 466 int(1) 467} 468 469-- Iteration 24 -- 470 471Warning: rsort() expects parameter 2 to be integer, resource given in %s on line %d 472bool(false) 473array(5) { 474 [0]=> 475 int(1) 476 [1]=> 477 int(5) 478 [2]=> 479 int(2) 480 [3]=> 481 int(3) 482 [4]=> 483 int(1) 484} 485Done 486