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