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