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