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