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