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 110--EXPECTF-- 111*** Testing rsort() : variation *** 112 113-- Iteration 1 -- 114bool(true) 115array(5) { 116 [0]=> 117 int(5) 118 [1]=> 119 int(3) 120 [2]=> 121 int(2) 122 [3]=> 123 int(1) 124 [4]=> 125 int(1) 126} 127 128-- Iteration 2 -- 129bool(true) 130array(5) { 131 [0]=> 132 int(5) 133 [1]=> 134 int(3) 135 [2]=> 136 int(2) 137 [3]=> 138 int(1) 139 [4]=> 140 int(1) 141} 142 143-- Iteration 3 -- 144bool(true) 145array(5) { 146 [0]=> 147 int(5) 148 [1]=> 149 int(3) 150 [2]=> 151 int(2) 152 [3]=> 153 int(1) 154 [4]=> 155 int(1) 156} 157 158-- Iteration 4 -- 159bool(true) 160array(5) { 161 [0]=> 162 int(5) 163 [1]=> 164 int(3) 165 [2]=> 166 int(2) 167 [3]=> 168 int(1) 169 [4]=> 170 int(1) 171} 172 173-- Iteration 5 -- 174bool(true) 175array(5) { 176 [0]=> 177 int(5) 178 [1]=> 179 int(3) 180 [2]=> 181 int(2) 182 [3]=> 183 int(1) 184 [4]=> 185 int(1) 186} 187 188-- Iteration 6 -- 189bool(true) 190array(5) { 191 [0]=> 192 int(5) 193 [1]=> 194 int(3) 195 [2]=> 196 int(2) 197 [3]=> 198 int(1) 199 [4]=> 200 int(1) 201} 202 203-- Iteration 7 -- 204bool(true) 205array(5) { 206 [0]=> 207 int(5) 208 [1]=> 209 int(3) 210 [2]=> 211 int(2) 212 [3]=> 213 int(1) 214 [4]=> 215 int(1) 216} 217 218-- Iteration 8 -- 219bool(true) 220array(5) { 221 [0]=> 222 int(5) 223 [1]=> 224 int(3) 225 [2]=> 226 int(2) 227 [3]=> 228 int(1) 229 [4]=> 230 int(1) 231} 232 233-- Iteration 9 -- 234bool(true) 235array(5) { 236 [0]=> 237 int(5) 238 [1]=> 239 int(3) 240 [2]=> 241 int(2) 242 [3]=> 243 int(1) 244 [4]=> 245 int(1) 246} 247 248-- Iteration 10 -- 249bool(true) 250array(5) { 251 [0]=> 252 int(5) 253 [1]=> 254 int(3) 255 [2]=> 256 int(2) 257 [3]=> 258 int(1) 259 [4]=> 260 int(1) 261} 262 263-- Iteration 11 -- 264bool(true) 265array(5) { 266 [0]=> 267 int(5) 268 [1]=> 269 int(3) 270 [2]=> 271 int(2) 272 [3]=> 273 int(1) 274 [4]=> 275 int(1) 276} 277 278-- Iteration 12 -- 279bool(true) 280array(5) { 281 [0]=> 282 int(5) 283 [1]=> 284 int(3) 285 [2]=> 286 int(2) 287 [3]=> 288 int(1) 289 [4]=> 290 int(1) 291} 292 293-- Iteration 13 -- 294bool(true) 295array(5) { 296 [0]=> 297 int(5) 298 [1]=> 299 int(3) 300 [2]=> 301 int(2) 302 [3]=> 303 int(1) 304 [4]=> 305 int(1) 306} 307 308-- Iteration 14 -- 309bool(true) 310array(5) { 311 [0]=> 312 int(5) 313 [1]=> 314 int(3) 315 [2]=> 316 int(2) 317 [3]=> 318 int(1) 319 [4]=> 320 int(1) 321} 322 323-- Iteration 15 -- 324bool(true) 325array(5) { 326 [0]=> 327 int(5) 328 [1]=> 329 int(3) 330 [2]=> 331 int(2) 332 [3]=> 333 int(1) 334 [4]=> 335 int(1) 336} 337 338-- Iteration 16 -- 339 340Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 341bool(false) 342array(5) { 343 [0]=> 344 int(1) 345 [1]=> 346 int(5) 347 [2]=> 348 int(2) 349 [3]=> 350 int(3) 351 [4]=> 352 int(1) 353} 354 355-- Iteration 17 -- 356 357Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 358bool(false) 359array(5) { 360 [0]=> 361 int(1) 362 [1]=> 363 int(5) 364 [2]=> 365 int(2) 366 [3]=> 367 int(3) 368 [4]=> 369 int(1) 370} 371 372-- Iteration 18 -- 373 374Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 375bool(false) 376array(5) { 377 [0]=> 378 int(1) 379 [1]=> 380 int(5) 381 [2]=> 382 int(2) 383 [3]=> 384 int(3) 385 [4]=> 386 int(1) 387} 388 389-- Iteration 19 -- 390 391Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 392bool(false) 393array(5) { 394 [0]=> 395 int(1) 396 [1]=> 397 int(5) 398 [2]=> 399 int(2) 400 [3]=> 401 int(3) 402 [4]=> 403 int(1) 404} 405 406-- Iteration 20 -- 407 408Warning: rsort() expects parameter 2 to be integer, string given in %s on line %d 409bool(false) 410array(5) { 411 [0]=> 412 int(1) 413 [1]=> 414 int(5) 415 [2]=> 416 int(2) 417 [3]=> 418 int(3) 419 [4]=> 420 int(1) 421} 422 423-- Iteration 21 -- 424 425Warning: rsort() expects parameter 2 to be integer, object given in %s on line %d 426bool(false) 427array(5) { 428 [0]=> 429 int(1) 430 [1]=> 431 int(5) 432 [2]=> 433 int(2) 434 [3]=> 435 int(3) 436 [4]=> 437 int(1) 438} 439 440-- Iteration 22 -- 441bool(true) 442array(5) { 443 [0]=> 444 int(5) 445 [1]=> 446 int(3) 447 [2]=> 448 int(2) 449 [3]=> 450 int(1) 451 [4]=> 452 int(1) 453} 454 455-- Iteration 23 -- 456bool(true) 457array(5) { 458 [0]=> 459 int(5) 460 [1]=> 461 int(3) 462 [2]=> 463 int(2) 464 [3]=> 465 int(1) 466 [4]=> 467 int(1) 468} 469 470-- Iteration 24 -- 471 472Warning: rsort() expects parameter 2 to be integer, resource given in %s on line %d 473bool(false) 474array(5) { 475 [0]=> 476 int(1) 477 [1]=> 478 int(5) 479 [2]=> 480 int(2) 481 [3]=> 482 int(3) 483 [4]=> 484 int(1) 485} 486Done 487