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