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