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