1--TEST-- 2Test token_get_all() function : usage variations - with control structure tokens 3--EXTENSIONS-- 4tokenizer 5--FILE-- 6<?php 7/* 8 * Using different control structure keywords 9 * if..else, elseif - T_IF(301), T_ELSEIF(302), T_ELSE(303) 10 * while - T_WHILE(318) 11 * do...while - T_DO(317) 12 * for - T_ENDFOR(320) 13 * foreach - T_ENDFOREACH(322) 14 * switch...case - T_ENDSWITCH(327), T_CASE(329) 15 * break - T_BREAK(331) 16 * continue - T_CONTINUE(332) 17*/ 18 19echo "*** Testing token_get_all() : for control structure tokens ***\n"; 20 21// if..elseif....else 22echo "-- with if..elseif..else..tokens --\n"; 23 24$source = '<?php 25if($a == true) { 26 echo "$a = true"; 27} 28elseif($a == false) { 29 echo false; 30} 31else 32 echo 1; 33?>'; 34 35var_dump( token_get_all($source)); 36 37// while..., do..while, break, continue 38echo "-- with while..., do..while, switch & continue tokens --\n"; 39 40$source = "<?php while(true) { 41echo 'True'; 42break; 43} 44do { 45continue; 46}while(false); ?>"; 47 48var_dump( token_get_all($source)); 49 50// for..., foreach( as ) 51echo "-- with for..foreach( as ) tokens --\n"; 52 53$source = '<?php for($count=0; $count < 5; $count++) { 54echo $count; 55} 56foreach($values as $index) { 57continue; 58} ?>'; 59 60var_dump( token_get_all($source)); 61 62// switch..case, default 63echo "-- with switch...case tokens --\n"; 64 65$source = '<?php switch($var) 66case 1: break; 67default: echo "default"; ?>'; 68 69var_dump( token_get_all($source)); 70 71echo "Done" 72?> 73--EXPECTF-- 74*** Testing token_get_all() : for control structure tokens *** 75-- with if..elseif..else..tokens -- 76array(48) { 77 [0]=> 78 array(3) { 79 [0]=> 80 int(%d) 81 [1]=> 82 string(6) "<?php 83" 84 [2]=> 85 int(1) 86 } 87 [1]=> 88 array(3) { 89 [0]=> 90 int(%d) 91 [1]=> 92 string(2) "if" 93 [2]=> 94 int(2) 95 } 96 [2]=> 97 string(1) "(" 98 [3]=> 99 array(3) { 100 [0]=> 101 int(%d) 102 [1]=> 103 string(2) "$a" 104 [2]=> 105 int(2) 106 } 107 [4]=> 108 array(3) { 109 [0]=> 110 int(%d) 111 [1]=> 112 string(1) " " 113 [2]=> 114 int(2) 115 } 116 [5]=> 117 array(3) { 118 [0]=> 119 int(%d) 120 [1]=> 121 string(2) "==" 122 [2]=> 123 int(2) 124 } 125 [6]=> 126 array(3) { 127 [0]=> 128 int(%d) 129 [1]=> 130 string(1) " " 131 [2]=> 132 int(2) 133 } 134 [7]=> 135 array(3) { 136 [0]=> 137 int(%d) 138 [1]=> 139 string(4) "true" 140 [2]=> 141 int(2) 142 } 143 [8]=> 144 string(1) ")" 145 [9]=> 146 array(3) { 147 [0]=> 148 int(%d) 149 [1]=> 150 string(1) " " 151 [2]=> 152 int(2) 153 } 154 [10]=> 155 string(1) "{" 156 [11]=> 157 array(3) { 158 [0]=> 159 int(%d) 160 [1]=> 161 string(6) " 162 " 163 [2]=> 164 int(2) 165 } 166 [12]=> 167 array(3) { 168 [0]=> 169 int(%d) 170 [1]=> 171 string(4) "echo" 172 [2]=> 173 int(%d) 174 } 175 [13]=> 176 array(3) { 177 [0]=> 178 int(%d) 179 [1]=> 180 string(1) " " 181 [2]=> 182 int(%d) 183 } 184 [14]=> 185 string(1) """ 186 [15]=> 187 array(3) { 188 [0]=> 189 int(%d) 190 [1]=> 191 string(2) "$a" 192 [2]=> 193 int(%d) 194 } 195 [16]=> 196 array(3) { 197 [0]=> 198 int(%d) 199 [1]=> 200 string(7) " = true" 201 [2]=> 202 int(%d) 203 } 204 [17]=> 205 string(1) """ 206 [18]=> 207 string(1) ";" 208 [19]=> 209 array(3) { 210 [0]=> 211 int(%d) 212 [1]=> 213 string(1) " 214" 215 [2]=> 216 int(%d) 217 } 218 [20]=> 219 string(1) "}" 220 [21]=> 221 array(3) { 222 [0]=> 223 int(%d) 224 [1]=> 225 string(1) " 226" 227 [2]=> 228 int(4) 229 } 230 [22]=> 231 array(3) { 232 [0]=> 233 int(%d) 234 [1]=> 235 string(6) "elseif" 236 [2]=> 237 int(5) 238 } 239 [23]=> 240 string(1) "(" 241 [24]=> 242 array(3) { 243 [0]=> 244 int(%d) 245 [1]=> 246 string(2) "$a" 247 [2]=> 248 int(5) 249 } 250 [25]=> 251 array(3) { 252 [0]=> 253 int(%d) 254 [1]=> 255 string(1) " " 256 [2]=> 257 int(5) 258 } 259 [26]=> 260 array(3) { 261 [0]=> 262 int(%d) 263 [1]=> 264 string(2) "==" 265 [2]=> 266 int(5) 267 } 268 [27]=> 269 array(3) { 270 [0]=> 271 int(%d) 272 [1]=> 273 string(1) " " 274 [2]=> 275 int(5) 276 } 277 [28]=> 278 array(3) { 279 [0]=> 280 int(%d) 281 [1]=> 282 string(5) "false" 283 [2]=> 284 int(5) 285 } 286 [29]=> 287 string(1) ")" 288 [30]=> 289 array(3) { 290 [0]=> 291 int(%d) 292 [1]=> 293 string(1) " " 294 [2]=> 295 int(5) 296 } 297 [31]=> 298 string(1) "{" 299 [32]=> 300 array(3) { 301 [0]=> 302 int(%d) 303 [1]=> 304 string(3) " 305 " 306 [2]=> 307 int(5) 308 } 309 [33]=> 310 array(3) { 311 [0]=> 312 int(%d) 313 [1]=> 314 string(4) "echo" 315 [2]=> 316 int(6) 317 } 318 [34]=> 319 array(3) { 320 [0]=> 321 int(%d) 322 [1]=> 323 string(1) " " 324 [2]=> 325 int(6) 326 } 327 [35]=> 328 array(3) { 329 [0]=> 330 int(%d) 331 [1]=> 332 string(5) "false" 333 [2]=> 334 int(6) 335 } 336 [36]=> 337 string(1) ";" 338 [37]=> 339 array(3) { 340 [0]=> 341 int(%d) 342 [1]=> 343 string(1) " 344" 345 [2]=> 346 int(6) 347 } 348 [38]=> 349 string(1) "}" 350 [39]=> 351 array(3) { 352 [0]=> 353 int(%d) 354 [1]=> 355 string(1) " 356" 357 [2]=> 358 int(7) 359 } 360 [40]=> 361 array(3) { 362 [0]=> 363 int(%d) 364 [1]=> 365 string(4) "else" 366 [2]=> 367 int(8) 368 } 369 [41]=> 370 array(3) { 371 [0]=> 372 int(%d) 373 [1]=> 374 string(3) " 375 " 376 [2]=> 377 int(8) 378 } 379 [42]=> 380 array(3) { 381 [0]=> 382 int(%d) 383 [1]=> 384 string(4) "echo" 385 [2]=> 386 int(9) 387 } 388 [43]=> 389 array(3) { 390 [0]=> 391 int(%d) 392 [1]=> 393 string(1) " " 394 [2]=> 395 int(9) 396 } 397 [44]=> 398 array(3) { 399 [0]=> 400 int(%d) 401 [1]=> 402 string(1) "1" 403 [2]=> 404 int(9) 405 } 406 [45]=> 407 string(1) ";" 408 [46]=> 409 array(3) { 410 [0]=> 411 int(%d) 412 [1]=> 413 string(1) " 414" 415 [2]=> 416 int(9) 417 } 418 [47]=> 419 array(3) { 420 [0]=> 421 int(%d) 422 [1]=> 423 string(2) "?>" 424 [2]=> 425 int(10) 426 } 427} 428-- with while..., do..while, switch & continue tokens -- 429array(33) { 430 [0]=> 431 array(3) { 432 [0]=> 433 int(%d) 434 [1]=> 435 string(6) "<?php " 436 [2]=> 437 int(1) 438 } 439 [1]=> 440 array(3) { 441 [0]=> 442 int(%d) 443 [1]=> 444 string(5) "while" 445 [2]=> 446 int(1) 447 } 448 [2]=> 449 string(1) "(" 450 [3]=> 451 array(3) { 452 [0]=> 453 int(%d) 454 [1]=> 455 string(4) "true" 456 [2]=> 457 int(1) 458 } 459 [4]=> 460 string(1) ")" 461 [5]=> 462 array(3) { 463 [0]=> 464 int(%d) 465 [1]=> 466 string(1) " " 467 [2]=> 468 int(1) 469 } 470 [6]=> 471 string(1) "{" 472 [7]=> 473 array(3) { 474 [0]=> 475 int(%d) 476 [1]=> 477 string(1) " 478" 479 [2]=> 480 int(1) 481 } 482 [8]=> 483 array(3) { 484 [0]=> 485 int(%d) 486 [1]=> 487 string(4) "echo" 488 [2]=> 489 int(2) 490 } 491 [9]=> 492 array(3) { 493 [0]=> 494 int(%d) 495 [1]=> 496 string(1) " " 497 [2]=> 498 int(2) 499 } 500 [10]=> 501 array(3) { 502 [0]=> 503 int(%d) 504 [1]=> 505 string(6) "'True'" 506 [2]=> 507 int(2) 508 } 509 [11]=> 510 string(1) ";" 511 [12]=> 512 array(3) { 513 [0]=> 514 int(%d) 515 [1]=> 516 string(1) " 517" 518 [2]=> 519 int(2) 520 } 521 [13]=> 522 array(3) { 523 [0]=> 524 int(%d) 525 [1]=> 526 string(5) "break" 527 [2]=> 528 int(%d) 529 } 530 [14]=> 531 string(1) ";" 532 [15]=> 533 array(3) { 534 [0]=> 535 int(%d) 536 [1]=> 537 string(1) " 538" 539 [2]=> 540 int(%d) 541 } 542 [16]=> 543 string(1) "}" 544 [17]=> 545 array(3) { 546 [0]=> 547 int(%d) 548 [1]=> 549 string(1) " 550" 551 [2]=> 552 int(4) 553 } 554 [18]=> 555 array(3) { 556 [0]=> 557 int(%d) 558 [1]=> 559 string(2) "do" 560 [2]=> 561 int(5) 562 } 563 [19]=> 564 array(3) { 565 [0]=> 566 int(%d) 567 [1]=> 568 string(1) " " 569 [2]=> 570 int(5) 571 } 572 [20]=> 573 string(1) "{" 574 [21]=> 575 array(3) { 576 [0]=> 577 int(%d) 578 [1]=> 579 string(1) " 580" 581 [2]=> 582 int(5) 583 } 584 [22]=> 585 array(3) { 586 [0]=> 587 int(%d) 588 [1]=> 589 string(8) "continue" 590 [2]=> 591 int(6) 592 } 593 [23]=> 594 string(1) ";" 595 [24]=> 596 array(3) { 597 [0]=> 598 int(%d) 599 [1]=> 600 string(1) " 601" 602 [2]=> 603 int(6) 604 } 605 [25]=> 606 string(1) "}" 607 [26]=> 608 array(3) { 609 [0]=> 610 int(%d) 611 [1]=> 612 string(5) "while" 613 [2]=> 614 int(7) 615 } 616 [27]=> 617 string(1) "(" 618 [28]=> 619 array(3) { 620 [0]=> 621 int(%d) 622 [1]=> 623 string(5) "false" 624 [2]=> 625 int(7) 626 } 627 [29]=> 628 string(1) ")" 629 [30]=> 630 string(1) ";" 631 [31]=> 632 array(3) { 633 [0]=> 634 int(%d) 635 [1]=> 636 string(1) " " 637 [2]=> 638 int(7) 639 } 640 [32]=> 641 array(3) { 642 [0]=> 643 int(%d) 644 [1]=> 645 string(2) "?>" 646 [2]=> 647 int(7) 648 } 649} 650-- with for..foreach( as ) tokens -- 651array(45) { 652 [0]=> 653 array(3) { 654 [0]=> 655 int(%d) 656 [1]=> 657 string(6) "<?php " 658 [2]=> 659 int(1) 660 } 661 [1]=> 662 array(3) { 663 [0]=> 664 int(%d) 665 [1]=> 666 string(3) "for" 667 [2]=> 668 int(1) 669 } 670 [2]=> 671 string(1) "(" 672 [3]=> 673 array(3) { 674 [0]=> 675 int(%d) 676 [1]=> 677 string(6) "$count" 678 [2]=> 679 int(1) 680 } 681 [4]=> 682 string(1) "=" 683 [5]=> 684 array(3) { 685 [0]=> 686 int(%d) 687 [1]=> 688 string(1) "0" 689 [2]=> 690 int(1) 691 } 692 [6]=> 693 string(1) ";" 694 [7]=> 695 array(3) { 696 [0]=> 697 int(%d) 698 [1]=> 699 string(1) " " 700 [2]=> 701 int(1) 702 } 703 [8]=> 704 array(3) { 705 [0]=> 706 int(%d) 707 [1]=> 708 string(6) "$count" 709 [2]=> 710 int(1) 711 } 712 [9]=> 713 array(3) { 714 [0]=> 715 int(%d) 716 [1]=> 717 string(1) " " 718 [2]=> 719 int(1) 720 } 721 [10]=> 722 string(1) "<" 723 [11]=> 724 array(3) { 725 [0]=> 726 int(%d) 727 [1]=> 728 string(1) " " 729 [2]=> 730 int(1) 731 } 732 [12]=> 733 array(3) { 734 [0]=> 735 int(%d) 736 [1]=> 737 string(1) "5" 738 [2]=> 739 int(1) 740 } 741 [13]=> 742 string(1) ";" 743 [14]=> 744 array(3) { 745 [0]=> 746 int(%d) 747 [1]=> 748 string(1) " " 749 [2]=> 750 int(1) 751 } 752 [15]=> 753 array(3) { 754 [0]=> 755 int(%d) 756 [1]=> 757 string(6) "$count" 758 [2]=> 759 int(1) 760 } 761 [16]=> 762 array(3) { 763 [0]=> 764 int(%d) 765 [1]=> 766 string(2) "++" 767 [2]=> 768 int(1) 769 } 770 [17]=> 771 string(1) ")" 772 [18]=> 773 array(3) { 774 [0]=> 775 int(%d) 776 [1]=> 777 string(1) " " 778 [2]=> 779 int(1) 780 } 781 [19]=> 782 string(1) "{" 783 [20]=> 784 array(3) { 785 [0]=> 786 int(%d) 787 [1]=> 788 string(1) " 789" 790 [2]=> 791 int(1) 792 } 793 [21]=> 794 array(3) { 795 [0]=> 796 int(%d) 797 [1]=> 798 string(4) "echo" 799 [2]=> 800 int(2) 801 } 802 [22]=> 803 array(3) { 804 [0]=> 805 int(%d) 806 [1]=> 807 string(1) " " 808 [2]=> 809 int(2) 810 } 811 [23]=> 812 array(3) { 813 [0]=> 814 int(%d) 815 [1]=> 816 string(6) "$count" 817 [2]=> 818 int(2) 819 } 820 [24]=> 821 string(1) ";" 822 [25]=> 823 array(3) { 824 [0]=> 825 int(%d) 826 [1]=> 827 string(1) " 828" 829 [2]=> 830 int(2) 831 } 832 [26]=> 833 string(1) "}" 834 [27]=> 835 array(3) { 836 [0]=> 837 int(%d) 838 [1]=> 839 string(1) " 840" 841 [2]=> 842 int(%d) 843 } 844 [28]=> 845 array(3) { 846 [0]=> 847 int(%d) 848 [1]=> 849 string(7) "foreach" 850 [2]=> 851 int(4) 852 } 853 [29]=> 854 string(1) "(" 855 [30]=> 856 array(3) { 857 [0]=> 858 int(%d) 859 [1]=> 860 string(7) "$values" 861 [2]=> 862 int(4) 863 } 864 [31]=> 865 array(3) { 866 [0]=> 867 int(%d) 868 [1]=> 869 string(1) " " 870 [2]=> 871 int(4) 872 } 873 [32]=> 874 array(3) { 875 [0]=> 876 int(%d) 877 [1]=> 878 string(2) "as" 879 [2]=> 880 int(4) 881 } 882 [33]=> 883 array(3) { 884 [0]=> 885 int(%d) 886 [1]=> 887 string(1) " " 888 [2]=> 889 int(4) 890 } 891 [34]=> 892 array(3) { 893 [0]=> 894 int(%d) 895 [1]=> 896 string(6) "$index" 897 [2]=> 898 int(4) 899 } 900 [35]=> 901 string(1) ")" 902 [36]=> 903 array(3) { 904 [0]=> 905 int(%d) 906 [1]=> 907 string(1) " " 908 [2]=> 909 int(4) 910 } 911 [37]=> 912 string(1) "{" 913 [38]=> 914 array(3) { 915 [0]=> 916 int(%d) 917 [1]=> 918 string(1) " 919" 920 [2]=> 921 int(4) 922 } 923 [39]=> 924 array(3) { 925 [0]=> 926 int(%d) 927 [1]=> 928 string(8) "continue" 929 [2]=> 930 int(5) 931 } 932 [40]=> 933 string(1) ";" 934 [41]=> 935 array(3) { 936 [0]=> 937 int(%d) 938 [1]=> 939 string(1) " 940" 941 [2]=> 942 int(5) 943 } 944 [42]=> 945 string(1) "}" 946 [43]=> 947 array(3) { 948 [0]=> 949 int(%d) 950 [1]=> 951 string(1) " " 952 [2]=> 953 int(6) 954 } 955 [44]=> 956 array(3) { 957 [0]=> 958 int(%d) 959 [1]=> 960 string(2) "?>" 961 [2]=> 962 int(6) 963 } 964} 965-- with switch...case tokens -- 966array(23) { 967 [0]=> 968 array(3) { 969 [0]=> 970 int(%d) 971 [1]=> 972 string(6) "<?php " 973 [2]=> 974 int(1) 975 } 976 [1]=> 977 array(3) { 978 [0]=> 979 int(%d) 980 [1]=> 981 string(6) "switch" 982 [2]=> 983 int(1) 984 } 985 [2]=> 986 string(1) "(" 987 [3]=> 988 array(3) { 989 [0]=> 990 int(%d) 991 [1]=> 992 string(4) "$var" 993 [2]=> 994 int(1) 995 } 996 [4]=> 997 string(1) ")" 998 [5]=> 999 array(3) { 1000 [0]=> 1001 int(%d) 1002 [1]=> 1003 string(1) " 1004" 1005 [2]=> 1006 int(1) 1007 } 1008 [6]=> 1009 array(3) { 1010 [0]=> 1011 int(%d) 1012 [1]=> 1013 string(4) "case" 1014 [2]=> 1015 int(2) 1016 } 1017 [7]=> 1018 array(3) { 1019 [0]=> 1020 int(%d) 1021 [1]=> 1022 string(1) " " 1023 [2]=> 1024 int(2) 1025 } 1026 [8]=> 1027 array(3) { 1028 [0]=> 1029 int(%d) 1030 [1]=> 1031 string(1) "1" 1032 [2]=> 1033 int(2) 1034 } 1035 [9]=> 1036 string(1) ":" 1037 [10]=> 1038 array(3) { 1039 [0]=> 1040 int(%d) 1041 [1]=> 1042 string(1) " " 1043 [2]=> 1044 int(2) 1045 } 1046 [11]=> 1047 array(3) { 1048 [0]=> 1049 int(%d) 1050 [1]=> 1051 string(5) "break" 1052 [2]=> 1053 int(2) 1054 } 1055 [12]=> 1056 string(1) ";" 1057 [13]=> 1058 array(3) { 1059 [0]=> 1060 int(%d) 1061 [1]=> 1062 string(1) " 1063" 1064 [2]=> 1065 int(2) 1066 } 1067 [14]=> 1068 array(3) { 1069 [0]=> 1070 int(%d) 1071 [1]=> 1072 string(7) "default" 1073 [2]=> 1074 int(%d) 1075 } 1076 [15]=> 1077 string(1) ":" 1078 [16]=> 1079 array(3) { 1080 [0]=> 1081 int(%d) 1082 [1]=> 1083 string(1) " " 1084 [2]=> 1085 int(%d) 1086 } 1087 [17]=> 1088 array(3) { 1089 [0]=> 1090 int(%d) 1091 [1]=> 1092 string(4) "echo" 1093 [2]=> 1094 int(%d) 1095 } 1096 [18]=> 1097 array(3) { 1098 [0]=> 1099 int(%d) 1100 [1]=> 1101 string(1) " " 1102 [2]=> 1103 int(%d) 1104 } 1105 [19]=> 1106 array(3) { 1107 [0]=> 1108 int(%d) 1109 [1]=> 1110 string(9) ""default"" 1111 [2]=> 1112 int(%d) 1113 } 1114 [20]=> 1115 string(1) ";" 1116 [21]=> 1117 array(3) { 1118 [0]=> 1119 int(%d) 1120 [1]=> 1121 string(1) " " 1122 [2]=> 1123 int(%d) 1124 } 1125 [22]=> 1126 array(3) { 1127 [0]=> 1128 int(%d) 1129 [1]=> 1130 string(2) "?>" 1131 [2]=> 1132 int(%d) 1133 } 1134} 1135Done 1136