1--TEST-- 2Test localtime() function : usage variation - Passing unexpected values to second argument 'associative_array'. 3--FILE-- 4<?php 5/* Prototype : array localtime([int timestamp [, bool associative_array]]) 6 * Description: Returns the results of the C system call localtime as an associative array 7 * if the associative_array argument is set to 1 other wise it is a regular array 8 * Source code: ext/date/php_date.c 9 * Alias to functions: 10 */ 11 12echo "*** Testing localtime() : usage variation ***\n"; 13 14date_default_timezone_set("UTC"); 15// Initialise function arguments not being substituted (if any) 16$timestamp = 10; 17 18//get an unset variable 19$unset_var = 10; 20unset ($unset_var); 21 22// define some classes 23class classWithToString 24{ 25 public function __toString() { 26 return "Class A object"; 27 } 28} 29 30class classWithoutToString 31{ 32} 33 34// heredoc string 35$heredoc = <<<EOT 36hello world 37EOT; 38 39// add arrays 40$index_array = array (1, 2, 3); 41$assoc_array = array ('one' => 1, 'two' => 2); 42 43//array of values to iterate over 44$inputs = array( 45 46 // int data 47 'int 0' => 0, 48 'int 1' => 1, 49 'int 12345' => 12345, 50 'int -12345' => -2345, 51 52 // float data 53 'float 10.5' => 10.5, 54 'float -10.5' => -10.5, 55 'float 12.3456789000e10' => 12.3456789000e10, 56 'float -12.3456789000e10' => -12.3456789000e10, 57 'float .5' => .5, 58 59 // array data 60 'empty array' => array(), 61 'int indexed array' => $index_array, 62 'associative array' => $assoc_array, 63 'nested arrays' => array('foo', $index_array, $assoc_array), 64 65 // null data 66 'uppercase NULL' => NULL, 67 'lowercase null' => null, 68 69 // boolean data 70 'lowercase true' => true, 71 'lowercase false' =>false, 72 'uppercase TRUE' =>TRUE, 73 'uppercase FALSE' =>FALSE, 74 75 // empty data 76 'empty string DQ' => "", 77 'empty string SQ' => '', 78 79 // string data 80 'string DQ' => "string", 81 'string SQ' => 'string', 82 'mixed case string' => "sTrInG", 83 'heredoc' => $heredoc, 84 85 // object data 86 'instance of classWithToString' => new classWithToString(), 87 'instance of classWithoutToString' => new classWithoutToString(), 88 89 // undefined data 90 'undefined var' => @$undefined_var, 91 92 // unset data 93 'unset var' => @$unset_var, 94); 95 96// loop through each element of the array for associative_array 97 98foreach($inputs as $key =>$value) { 99 echo "\n--$key--\n"; 100 var_dump( localtime($timestamp, $value) ); 101}; 102 103?> 104===DONE=== 105--EXPECTF-- 106*** Testing localtime() : usage variation *** 107 108--int 0-- 109array(9) { 110 [0]=> 111 int(10) 112 [1]=> 113 int(0) 114 [2]=> 115 int(0) 116 [3]=> 117 int(1) 118 [4]=> 119 int(0) 120 [5]=> 121 int(70) 122 [6]=> 123 int(4) 124 [7]=> 125 int(0) 126 [8]=> 127 int(0) 128} 129 130--int 1-- 131array(9) { 132 ["tm_sec"]=> 133 int(10) 134 ["tm_min"]=> 135 int(0) 136 ["tm_hour"]=> 137 int(0) 138 ["tm_mday"]=> 139 int(1) 140 ["tm_mon"]=> 141 int(0) 142 ["tm_year"]=> 143 int(70) 144 ["tm_wday"]=> 145 int(4) 146 ["tm_yday"]=> 147 int(0) 148 ["tm_isdst"]=> 149 int(0) 150} 151 152--int 12345-- 153array(9) { 154 ["tm_sec"]=> 155 int(10) 156 ["tm_min"]=> 157 int(0) 158 ["tm_hour"]=> 159 int(0) 160 ["tm_mday"]=> 161 int(1) 162 ["tm_mon"]=> 163 int(0) 164 ["tm_year"]=> 165 int(70) 166 ["tm_wday"]=> 167 int(4) 168 ["tm_yday"]=> 169 int(0) 170 ["tm_isdst"]=> 171 int(0) 172} 173 174--int -12345-- 175array(9) { 176 ["tm_sec"]=> 177 int(10) 178 ["tm_min"]=> 179 int(0) 180 ["tm_hour"]=> 181 int(0) 182 ["tm_mday"]=> 183 int(1) 184 ["tm_mon"]=> 185 int(0) 186 ["tm_year"]=> 187 int(70) 188 ["tm_wday"]=> 189 int(4) 190 ["tm_yday"]=> 191 int(0) 192 ["tm_isdst"]=> 193 int(0) 194} 195 196--float 10.5-- 197array(9) { 198 ["tm_sec"]=> 199 int(10) 200 ["tm_min"]=> 201 int(0) 202 ["tm_hour"]=> 203 int(0) 204 ["tm_mday"]=> 205 int(1) 206 ["tm_mon"]=> 207 int(0) 208 ["tm_year"]=> 209 int(70) 210 ["tm_wday"]=> 211 int(4) 212 ["tm_yday"]=> 213 int(0) 214 ["tm_isdst"]=> 215 int(0) 216} 217 218--float -10.5-- 219array(9) { 220 ["tm_sec"]=> 221 int(10) 222 ["tm_min"]=> 223 int(0) 224 ["tm_hour"]=> 225 int(0) 226 ["tm_mday"]=> 227 int(1) 228 ["tm_mon"]=> 229 int(0) 230 ["tm_year"]=> 231 int(70) 232 ["tm_wday"]=> 233 int(4) 234 ["tm_yday"]=> 235 int(0) 236 ["tm_isdst"]=> 237 int(0) 238} 239 240--float 12.3456789000e10-- 241array(9) { 242 ["tm_sec"]=> 243 int(10) 244 ["tm_min"]=> 245 int(0) 246 ["tm_hour"]=> 247 int(0) 248 ["tm_mday"]=> 249 int(1) 250 ["tm_mon"]=> 251 int(0) 252 ["tm_year"]=> 253 int(70) 254 ["tm_wday"]=> 255 int(4) 256 ["tm_yday"]=> 257 int(0) 258 ["tm_isdst"]=> 259 int(0) 260} 261 262--float -12.3456789000e10-- 263array(9) { 264 ["tm_sec"]=> 265 int(10) 266 ["tm_min"]=> 267 int(0) 268 ["tm_hour"]=> 269 int(0) 270 ["tm_mday"]=> 271 int(1) 272 ["tm_mon"]=> 273 int(0) 274 ["tm_year"]=> 275 int(70) 276 ["tm_wday"]=> 277 int(4) 278 ["tm_yday"]=> 279 int(0) 280 ["tm_isdst"]=> 281 int(0) 282} 283 284--float .5-- 285array(9) { 286 ["tm_sec"]=> 287 int(10) 288 ["tm_min"]=> 289 int(0) 290 ["tm_hour"]=> 291 int(0) 292 ["tm_mday"]=> 293 int(1) 294 ["tm_mon"]=> 295 int(0) 296 ["tm_year"]=> 297 int(70) 298 ["tm_wday"]=> 299 int(4) 300 ["tm_yday"]=> 301 int(0) 302 ["tm_isdst"]=> 303 int(0) 304} 305 306--empty array-- 307 308Warning: localtime() expects parameter 2 to be bool, array given in %s on line %d 309bool(false) 310 311--int indexed array-- 312 313Warning: localtime() expects parameter 2 to be bool, array given in %s on line %d 314bool(false) 315 316--associative array-- 317 318Warning: localtime() expects parameter 2 to be bool, array given in %s on line %d 319bool(false) 320 321--nested arrays-- 322 323Warning: localtime() expects parameter 2 to be bool, array given in %s on line %d 324bool(false) 325 326--uppercase NULL-- 327array(9) { 328 [0]=> 329 int(10) 330 [1]=> 331 int(0) 332 [2]=> 333 int(0) 334 [3]=> 335 int(1) 336 [4]=> 337 int(0) 338 [5]=> 339 int(70) 340 [6]=> 341 int(4) 342 [7]=> 343 int(0) 344 [8]=> 345 int(0) 346} 347 348--lowercase null-- 349array(9) { 350 [0]=> 351 int(10) 352 [1]=> 353 int(0) 354 [2]=> 355 int(0) 356 [3]=> 357 int(1) 358 [4]=> 359 int(0) 360 [5]=> 361 int(70) 362 [6]=> 363 int(4) 364 [7]=> 365 int(0) 366 [8]=> 367 int(0) 368} 369 370--lowercase true-- 371array(9) { 372 ["tm_sec"]=> 373 int(10) 374 ["tm_min"]=> 375 int(0) 376 ["tm_hour"]=> 377 int(0) 378 ["tm_mday"]=> 379 int(1) 380 ["tm_mon"]=> 381 int(0) 382 ["tm_year"]=> 383 int(70) 384 ["tm_wday"]=> 385 int(4) 386 ["tm_yday"]=> 387 int(0) 388 ["tm_isdst"]=> 389 int(0) 390} 391 392--lowercase false-- 393array(9) { 394 [0]=> 395 int(10) 396 [1]=> 397 int(0) 398 [2]=> 399 int(0) 400 [3]=> 401 int(1) 402 [4]=> 403 int(0) 404 [5]=> 405 int(70) 406 [6]=> 407 int(4) 408 [7]=> 409 int(0) 410 [8]=> 411 int(0) 412} 413 414--uppercase TRUE-- 415array(9) { 416 ["tm_sec"]=> 417 int(10) 418 ["tm_min"]=> 419 int(0) 420 ["tm_hour"]=> 421 int(0) 422 ["tm_mday"]=> 423 int(1) 424 ["tm_mon"]=> 425 int(0) 426 ["tm_year"]=> 427 int(70) 428 ["tm_wday"]=> 429 int(4) 430 ["tm_yday"]=> 431 int(0) 432 ["tm_isdst"]=> 433 int(0) 434} 435 436--uppercase FALSE-- 437array(9) { 438 [0]=> 439 int(10) 440 [1]=> 441 int(0) 442 [2]=> 443 int(0) 444 [3]=> 445 int(1) 446 [4]=> 447 int(0) 448 [5]=> 449 int(70) 450 [6]=> 451 int(4) 452 [7]=> 453 int(0) 454 [8]=> 455 int(0) 456} 457 458--empty string DQ-- 459array(9) { 460 [0]=> 461 int(10) 462 [1]=> 463 int(0) 464 [2]=> 465 int(0) 466 [3]=> 467 int(1) 468 [4]=> 469 int(0) 470 [5]=> 471 int(70) 472 [6]=> 473 int(4) 474 [7]=> 475 int(0) 476 [8]=> 477 int(0) 478} 479 480--empty string SQ-- 481array(9) { 482 [0]=> 483 int(10) 484 [1]=> 485 int(0) 486 [2]=> 487 int(0) 488 [3]=> 489 int(1) 490 [4]=> 491 int(0) 492 [5]=> 493 int(70) 494 [6]=> 495 int(4) 496 [7]=> 497 int(0) 498 [8]=> 499 int(0) 500} 501 502--string DQ-- 503array(9) { 504 ["tm_sec"]=> 505 int(10) 506 ["tm_min"]=> 507 int(0) 508 ["tm_hour"]=> 509 int(0) 510 ["tm_mday"]=> 511 int(1) 512 ["tm_mon"]=> 513 int(0) 514 ["tm_year"]=> 515 int(70) 516 ["tm_wday"]=> 517 int(4) 518 ["tm_yday"]=> 519 int(0) 520 ["tm_isdst"]=> 521 int(0) 522} 523 524--string SQ-- 525array(9) { 526 ["tm_sec"]=> 527 int(10) 528 ["tm_min"]=> 529 int(0) 530 ["tm_hour"]=> 531 int(0) 532 ["tm_mday"]=> 533 int(1) 534 ["tm_mon"]=> 535 int(0) 536 ["tm_year"]=> 537 int(70) 538 ["tm_wday"]=> 539 int(4) 540 ["tm_yday"]=> 541 int(0) 542 ["tm_isdst"]=> 543 int(0) 544} 545 546--mixed case string-- 547array(9) { 548 ["tm_sec"]=> 549 int(10) 550 ["tm_min"]=> 551 int(0) 552 ["tm_hour"]=> 553 int(0) 554 ["tm_mday"]=> 555 int(1) 556 ["tm_mon"]=> 557 int(0) 558 ["tm_year"]=> 559 int(70) 560 ["tm_wday"]=> 561 int(4) 562 ["tm_yday"]=> 563 int(0) 564 ["tm_isdst"]=> 565 int(0) 566} 567 568--heredoc-- 569array(9) { 570 ["tm_sec"]=> 571 int(10) 572 ["tm_min"]=> 573 int(0) 574 ["tm_hour"]=> 575 int(0) 576 ["tm_mday"]=> 577 int(1) 578 ["tm_mon"]=> 579 int(0) 580 ["tm_year"]=> 581 int(70) 582 ["tm_wday"]=> 583 int(4) 584 ["tm_yday"]=> 585 int(0) 586 ["tm_isdst"]=> 587 int(0) 588} 589 590--instance of classWithToString-- 591 592Warning: localtime() expects parameter 2 to be bool, object given in %s on line %d 593bool(false) 594 595--instance of classWithoutToString-- 596 597Warning: localtime() expects parameter 2 to be bool, object given in %s on line %d 598bool(false) 599 600--undefined var-- 601array(9) { 602 [0]=> 603 int(10) 604 [1]=> 605 int(0) 606 [2]=> 607 int(0) 608 [3]=> 609 int(1) 610 [4]=> 611 int(0) 612 [5]=> 613 int(70) 614 [6]=> 615 int(4) 616 [7]=> 617 int(0) 618 [8]=> 619 int(0) 620} 621 622--unset var-- 623array(9) { 624 [0]=> 625 int(10) 626 [1]=> 627 int(0) 628 [2]=> 629 int(0) 630 [3]=> 631 int(1) 632 [4]=> 633 int(0) 634 [5]=> 635 int(70) 636 [6]=> 637 int(4) 638 [7]=> 639 int(0) 640 [8]=> 641 int(0) 642} 643===DONE=== 644