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