1--TEST-- 2Test token_get_all() function : usage variations - with constant tokens 3--SKIPIF-- 4<?php if (!extension_loaded("tokenizer")) print "skip"; ?> 5--FILE-- 6<?php 7/* Prototype : array token_get_all(string $source) 8 * Description: splits the given source into an array of PHP languange tokens 9 * Source code: ext/tokenizer/tokenizer.c 10*/ 11 12/* 13 * Using different types of constants in 'source' string to check them for token 14 * integer const - T_LNUMBER(305) 15 * float/double/real const - T_DNUMBER(306) 16 * string cosnt - T_CONSTANT_ESCAPED_STRING(315) 17 * bool const (no tokens specified) - T_UNKNOWN(307) 18 * null const (no tokens specified) - T_UNKNOWN(307) 19*/ 20 21echo "*** Testing token_get_all() : 'source' string with different constants ***\n"; 22 23$a = 1; 24$b = 0; 25 26$source = array ( 27 // int const 28 '<?php $a = 1 + 034; $b = $a + 0x3F; ?>', 29 30 // float const 31 '<?php $a = 0.23E-2 + 0.43e2 + 0.5; ?>', 32 33 // string const 34 '<?php $a = "hello ".\'world\'; ?>', 35 36 // bool const 37 "<?php \$a = (\$b)? true : false; ?>", 38 "<?php \$b = (\$a)? FALSE : TRUE; ?>", 39 40 // null const 41 '<?php $b = null | NULL; ?>' 42); 43for($count = 0; $count < count($source); $count++) { 44 echo "-- Iteration ".($count + 1)." --\n"; 45 var_dump( token_get_all($source[$count])); 46} 47 48echo "Done" 49?> 50--EXPECTF-- 51*** Testing token_get_all() : 'source' string with different constants *** 52-- Iteration 1 -- 53array(24) { 54 [0]=> 55 array(3) { 56 [0]=> 57 int(%d) 58 [1]=> 59 string(6) "<?php " 60 [2]=> 61 int(1) 62 } 63 [1]=> 64 array(3) { 65 [0]=> 66 int(%d) 67 [1]=> 68 string(2) "$a" 69 [2]=> 70 int(1) 71 } 72 [2]=> 73 array(3) { 74 [0]=> 75 int(%d) 76 [1]=> 77 string(1) " " 78 [2]=> 79 int(1) 80 } 81 [3]=> 82 string(1) "=" 83 [4]=> 84 array(3) { 85 [0]=> 86 int(%d) 87 [1]=> 88 string(1) " " 89 [2]=> 90 int(1) 91 } 92 [5]=> 93 array(3) { 94 [0]=> 95 int(%d) 96 [1]=> 97 string(1) "1" 98 [2]=> 99 int(1) 100 } 101 [6]=> 102 array(3) { 103 [0]=> 104 int(%d) 105 [1]=> 106 string(1) " " 107 [2]=> 108 int(1) 109 } 110 [7]=> 111 string(1) "+" 112 [8]=> 113 array(3) { 114 [0]=> 115 int(%d) 116 [1]=> 117 string(1) " " 118 [2]=> 119 int(1) 120 } 121 [9]=> 122 array(3) { 123 [0]=> 124 int(%d) 125 [1]=> 126 string(3) "034" 127 [2]=> 128 int(1) 129 } 130 [10]=> 131 string(1) ";" 132 [11]=> 133 array(3) { 134 [0]=> 135 int(%d) 136 [1]=> 137 string(1) " " 138 [2]=> 139 int(1) 140 } 141 [12]=> 142 array(3) { 143 [0]=> 144 int(%d) 145 [1]=> 146 string(2) "$b" 147 [2]=> 148 int(1) 149 } 150 [13]=> 151 array(3) { 152 [0]=> 153 int(%d) 154 [1]=> 155 string(1) " " 156 [2]=> 157 int(1) 158 } 159 [14]=> 160 string(1) "=" 161 [15]=> 162 array(3) { 163 [0]=> 164 int(%d) 165 [1]=> 166 string(1) " " 167 [2]=> 168 int(1) 169 } 170 [16]=> 171 array(3) { 172 [0]=> 173 int(%d) 174 [1]=> 175 string(2) "$a" 176 [2]=> 177 int(1) 178 } 179 [17]=> 180 array(3) { 181 [0]=> 182 int(%d) 183 [1]=> 184 string(1) " " 185 [2]=> 186 int(1) 187 } 188 [18]=> 189 string(1) "+" 190 [19]=> 191 array(3) { 192 [0]=> 193 int(%d) 194 [1]=> 195 string(1) " " 196 [2]=> 197 int(1) 198 } 199 [20]=> 200 array(3) { 201 [0]=> 202 int(%d) 203 [1]=> 204 string(4) "0x3F" 205 [2]=> 206 int(1) 207 } 208 [21]=> 209 string(1) ";" 210 [22]=> 211 array(3) { 212 [0]=> 213 int(%d) 214 [1]=> 215 string(1) " " 216 [2]=> 217 int(1) 218 } 219 [23]=> 220 array(3) { 221 [0]=> 222 int(%d) 223 [1]=> 224 string(2) "?>" 225 [2]=> 226 int(1) 227 } 228} 229-- Iteration 2 -- 230array(17) { 231 [0]=> 232 array(3) { 233 [0]=> 234 int(%d) 235 [1]=> 236 string(6) "<?php " 237 [2]=> 238 int(1) 239 } 240 [1]=> 241 array(3) { 242 [0]=> 243 int(%d) 244 [1]=> 245 string(2) "$a" 246 [2]=> 247 int(1) 248 } 249 [2]=> 250 array(3) { 251 [0]=> 252 int(%d) 253 [1]=> 254 string(1) " " 255 [2]=> 256 int(1) 257 } 258 [3]=> 259 string(1) "=" 260 [4]=> 261 array(3) { 262 [0]=> 263 int(%d) 264 [1]=> 265 string(1) " " 266 [2]=> 267 int(1) 268 } 269 [5]=> 270 array(3) { 271 [0]=> 272 int(%d) 273 [1]=> 274 string(7) "0.23E-2" 275 [2]=> 276 int(1) 277 } 278 [6]=> 279 array(3) { 280 [0]=> 281 int(%d) 282 [1]=> 283 string(1) " " 284 [2]=> 285 int(1) 286 } 287 [7]=> 288 string(1) "+" 289 [8]=> 290 array(3) { 291 [0]=> 292 int(%d) 293 [1]=> 294 string(1) " " 295 [2]=> 296 int(1) 297 } 298 [9]=> 299 array(3) { 300 [0]=> 301 int(%d) 302 [1]=> 303 string(6) "0.43e2" 304 [2]=> 305 int(1) 306 } 307 [10]=> 308 array(3) { 309 [0]=> 310 int(%d) 311 [1]=> 312 string(1) " " 313 [2]=> 314 int(1) 315 } 316 [11]=> 317 string(1) "+" 318 [12]=> 319 array(3) { 320 [0]=> 321 int(%d) 322 [1]=> 323 string(1) " " 324 [2]=> 325 int(1) 326 } 327 [13]=> 328 array(3) { 329 [0]=> 330 int(%d) 331 [1]=> 332 string(3) "0.5" 333 [2]=> 334 int(1) 335 } 336 [14]=> 337 string(1) ";" 338 [15]=> 339 array(3) { 340 [0]=> 341 int(%d) 342 [1]=> 343 string(1) " " 344 [2]=> 345 int(1) 346 } 347 [16]=> 348 array(3) { 349 [0]=> 350 int(%d) 351 [1]=> 352 string(2) "?>" 353 [2]=> 354 int(1) 355 } 356} 357-- Iteration 3 -- 358array(11) { 359 [0]=> 360 array(3) { 361 [0]=> 362 int(%d) 363 [1]=> 364 string(6) "<?php " 365 [2]=> 366 int(1) 367 } 368 [1]=> 369 array(3) { 370 [0]=> 371 int(%d) 372 [1]=> 373 string(2) "$a" 374 [2]=> 375 int(1) 376 } 377 [2]=> 378 array(3) { 379 [0]=> 380 int(%d) 381 [1]=> 382 string(1) " " 383 [2]=> 384 int(1) 385 } 386 [3]=> 387 string(1) "=" 388 [4]=> 389 array(3) { 390 [0]=> 391 int(%d) 392 [1]=> 393 string(1) " " 394 [2]=> 395 int(1) 396 } 397 [5]=> 398 array(3) { 399 [0]=> 400 int(%d) 401 [1]=> 402 string(8) ""hello "" 403 [2]=> 404 int(1) 405 } 406 [6]=> 407 string(1) "." 408 [7]=> 409 array(3) { 410 [0]=> 411 int(%d) 412 [1]=> 413 string(7) "'world'" 414 [2]=> 415 int(1) 416 } 417 [8]=> 418 string(1) ";" 419 [9]=> 420 array(3) { 421 [0]=> 422 int(%d) 423 [1]=> 424 string(1) " " 425 [2]=> 426 int(1) 427 } 428 [10]=> 429 array(3) { 430 [0]=> 431 int(%d) 432 [1]=> 433 string(2) "?>" 434 [2]=> 435 int(1) 436 } 437} 438-- Iteration 4 -- 439array(18) { 440 [0]=> 441 array(3) { 442 [0]=> 443 int(%d) 444 [1]=> 445 string(6) "<?php " 446 [2]=> 447 int(1) 448 } 449 [1]=> 450 array(3) { 451 [0]=> 452 int(%d) 453 [1]=> 454 string(2) "$a" 455 [2]=> 456 int(1) 457 } 458 [2]=> 459 array(3) { 460 [0]=> 461 int(%d) 462 [1]=> 463 string(1) " " 464 [2]=> 465 int(1) 466 } 467 [3]=> 468 string(1) "=" 469 [4]=> 470 array(3) { 471 [0]=> 472 int(%d) 473 [1]=> 474 string(1) " " 475 [2]=> 476 int(1) 477 } 478 [5]=> 479 string(1) "(" 480 [6]=> 481 array(3) { 482 [0]=> 483 int(%d) 484 [1]=> 485 string(2) "$b" 486 [2]=> 487 int(1) 488 } 489 [7]=> 490 string(1) ")" 491 [8]=> 492 string(1) "?" 493 [9]=> 494 array(3) { 495 [0]=> 496 int(%d) 497 [1]=> 498 string(1) " " 499 [2]=> 500 int(1) 501 } 502 [10]=> 503 array(3) { 504 [0]=> 505 int(%d) 506 [1]=> 507 string(4) "true" 508 [2]=> 509 int(1) 510 } 511 [11]=> 512 array(3) { 513 [0]=> 514 int(%d) 515 [1]=> 516 string(1) " " 517 [2]=> 518 int(1) 519 } 520 [12]=> 521 string(1) ":" 522 [13]=> 523 array(3) { 524 [0]=> 525 int(%d) 526 [1]=> 527 string(1) " " 528 [2]=> 529 int(1) 530 } 531 [14]=> 532 array(3) { 533 [0]=> 534 int(%d) 535 [1]=> 536 string(5) "false" 537 [2]=> 538 int(1) 539 } 540 [15]=> 541 string(1) ";" 542 [16]=> 543 array(3) { 544 [0]=> 545 int(%d) 546 [1]=> 547 string(1) " " 548 [2]=> 549 int(1) 550 } 551 [17]=> 552 array(3) { 553 [0]=> 554 int(%d) 555 [1]=> 556 string(2) "?>" 557 [2]=> 558 int(1) 559 } 560} 561-- Iteration 5 -- 562array(18) { 563 [0]=> 564 array(3) { 565 [0]=> 566 int(%d) 567 [1]=> 568 string(6) "<?php " 569 [2]=> 570 int(1) 571 } 572 [1]=> 573 array(3) { 574 [0]=> 575 int(%d) 576 [1]=> 577 string(2) "$b" 578 [2]=> 579 int(1) 580 } 581 [2]=> 582 array(3) { 583 [0]=> 584 int(%d) 585 [1]=> 586 string(1) " " 587 [2]=> 588 int(1) 589 } 590 [3]=> 591 string(1) "=" 592 [4]=> 593 array(3) { 594 [0]=> 595 int(%d) 596 [1]=> 597 string(1) " " 598 [2]=> 599 int(1) 600 } 601 [5]=> 602 string(1) "(" 603 [6]=> 604 array(3) { 605 [0]=> 606 int(%d) 607 [1]=> 608 string(2) "$a" 609 [2]=> 610 int(1) 611 } 612 [7]=> 613 string(1) ")" 614 [8]=> 615 string(1) "?" 616 [9]=> 617 array(3) { 618 [0]=> 619 int(%d) 620 [1]=> 621 string(1) " " 622 [2]=> 623 int(1) 624 } 625 [10]=> 626 array(3) { 627 [0]=> 628 int(%d) 629 [1]=> 630 string(5) "FALSE" 631 [2]=> 632 int(1) 633 } 634 [11]=> 635 array(3) { 636 [0]=> 637 int(%d) 638 [1]=> 639 string(1) " " 640 [2]=> 641 int(1) 642 } 643 [12]=> 644 string(1) ":" 645 [13]=> 646 array(3) { 647 [0]=> 648 int(%d) 649 [1]=> 650 string(1) " " 651 [2]=> 652 int(1) 653 } 654 [14]=> 655 array(3) { 656 [0]=> 657 int(%d) 658 [1]=> 659 string(4) "TRUE" 660 [2]=> 661 int(1) 662 } 663 [15]=> 664 string(1) ";" 665 [16]=> 666 array(3) { 667 [0]=> 668 int(%d) 669 [1]=> 670 string(1) " " 671 [2]=> 672 int(1) 673 } 674 [17]=> 675 array(3) { 676 [0]=> 677 int(%d) 678 [1]=> 679 string(2) "?>" 680 [2]=> 681 int(1) 682 } 683} 684-- Iteration 6 -- 685array(13) { 686 [0]=> 687 array(3) { 688 [0]=> 689 int(%d) 690 [1]=> 691 string(6) "<?php " 692 [2]=> 693 int(1) 694 } 695 [1]=> 696 array(3) { 697 [0]=> 698 int(%d) 699 [1]=> 700 string(2) "$b" 701 [2]=> 702 int(1) 703 } 704 [2]=> 705 array(3) { 706 [0]=> 707 int(%d) 708 [1]=> 709 string(1) " " 710 [2]=> 711 int(1) 712 } 713 [3]=> 714 string(1) "=" 715 [4]=> 716 array(3) { 717 [0]=> 718 int(%d) 719 [1]=> 720 string(1) " " 721 [2]=> 722 int(1) 723 } 724 [5]=> 725 array(3) { 726 [0]=> 727 int(%d) 728 [1]=> 729 string(4) "null" 730 [2]=> 731 int(1) 732 } 733 [6]=> 734 array(3) { 735 [0]=> 736 int(%d) 737 [1]=> 738 string(1) " " 739 [2]=> 740 int(1) 741 } 742 [7]=> 743 string(1) "|" 744 [8]=> 745 array(3) { 746 [0]=> 747 int(%d) 748 [1]=> 749 string(1) " " 750 [2]=> 751 int(1) 752 } 753 [9]=> 754 array(3) { 755 [0]=> 756 int(%d) 757 [1]=> 758 string(4) "NULL" 759 [2]=> 760 int(1) 761 } 762 [10]=> 763 string(1) ";" 764 [11]=> 765 array(3) { 766 [0]=> 767 int(%d) 768 [1]=> 769 string(1) " " 770 [2]=> 771 int(1) 772 } 773 [12]=> 774 array(3) { 775 [0]=> 776 int(%d) 777 [1]=> 778 string(2) "?>" 779 [2]=> 780 int(1) 781 } 782} 783Done 784