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