1--TEST--
2Test token_get_all() function : usage variations - with predefined language constants
3--EXTENSIONS--
4tokenizer
5--FILE--
6<?php
7/*
8 * Testing token_get_all() with following predefined language constants:
9 *   __FILE__     - T_FILE
10 *   __CLASS__    - T_CLASS_C
11 *   __TRAIT__    - T_TRAIT_C
12 *   __FUNCTION__ - T_FUNC_C
13 *   __LINE__     - T_LINE
14 *   __METHOD__   - T_METHOD_C
15*/
16
17echo "*** Testing token_get_all() : with language constants ***\n";
18
19// parsing __FILE__ token
20echo "-- with FILE --\n";
21$source = "<?php
22\$fp =  fopen(__FILE__, 'r');
23?>";
24var_dump( token_get_all($source));
25
26// parsing __CLASS__, __TRAIT__ and __FUNCTION__ tokens
27echo "-- with CLASS, TRAIT and FUNCTION --\n";
28$source = '<?php
29class MyClass
30{
31  echo  __CLASS__;
32  echo  __TRAIT__;
33  function myFunction()
34  {  echo  __FUNCTION__; }
35}
36?>';
37var_dump( token_get_all($source));
38
39// parsing __LINE__ and __METHOD__ tokens
40echo "-- with LINE and METHOD --\n";
41$source = '<?php
42  $a = __LINE__;
43  $b = $b.__METHOD__;
44?>';
45var_dump( token_get_all($source));
46
47echo "Done"
48?>
49--EXPECTF--
50*** Testing token_get_all() : with language constants ***
51-- with FILE --
52array(15) {
53  [0]=>
54  array(3) {
55    [0]=>
56    int(%d)
57    [1]=>
58    string(6) "<?php
59"
60    [2]=>
61    int(1)
62  }
63  [1]=>
64  array(3) {
65    [0]=>
66    int(%d)
67    [1]=>
68    string(3) "$fp"
69    [2]=>
70    int(2)
71  }
72  [2]=>
73  array(3) {
74    [0]=>
75    int(%d)
76    [1]=>
77    string(1) " "
78    [2]=>
79    int(2)
80  }
81  [3]=>
82  string(1) "="
83  [4]=>
84  array(3) {
85    [0]=>
86    int(%d)
87    [1]=>
88    string(2) "  "
89    [2]=>
90    int(2)
91  }
92  [5]=>
93  array(3) {
94    [0]=>
95    int(%d)
96    [1]=>
97    string(5) "fopen"
98    [2]=>
99    int(2)
100  }
101  [6]=>
102  string(1) "("
103  [7]=>
104  array(3) {
105    [0]=>
106    int(%d)
107    [1]=>
108    string(8) "__FILE__"
109    [2]=>
110    int(2)
111  }
112  [8]=>
113  string(1) ","
114  [9]=>
115  array(3) {
116    [0]=>
117    int(%d)
118    [1]=>
119    string(1) " "
120    [2]=>
121    int(2)
122  }
123  [10]=>
124  array(3) {
125    [0]=>
126    int(%d)
127    [1]=>
128    string(3) "'r'"
129    [2]=>
130    int(2)
131  }
132  [11]=>
133  string(1) ")"
134  [12]=>
135  string(1) ";"
136  [13]=>
137  array(3) {
138    [0]=>
139    int(%d)
140    [1]=>
141    string(1) "
142"
143    [2]=>
144    int(2)
145  }
146  [14]=>
147  array(3) {
148    [0]=>
149    int(%d)
150    [1]=>
151    string(2) "?>"
152    [2]=>
153    int(%d)
154  }
155}
156-- with CLASS, TRAIT and FUNCTION --
157array(35) {
158  [0]=>
159  array(3) {
160    [0]=>
161    int(%d)
162    [1]=>
163    string(6) "<?php
164"
165    [2]=>
166    int(1)
167  }
168  [1]=>
169  array(3) {
170    [0]=>
171    int(%d)
172    [1]=>
173    string(5) "class"
174    [2]=>
175    int(2)
176  }
177  [2]=>
178  array(3) {
179    [0]=>
180    int(%d)
181    [1]=>
182    string(1) " "
183    [2]=>
184    int(2)
185  }
186  [3]=>
187  array(3) {
188    [0]=>
189    int(%d)
190    [1]=>
191    string(7) "MyClass"
192    [2]=>
193    int(2)
194  }
195  [4]=>
196  array(3) {
197    [0]=>
198    int(%d)
199    [1]=>
200    string(1) "
201"
202    [2]=>
203    int(2)
204  }
205  [5]=>
206  string(1) "{"
207  [6]=>
208  array(3) {
209    [0]=>
210    int(%d)
211    [1]=>
212    string(3) "
213  "
214    [2]=>
215    int(%d)
216  }
217  [7]=>
218  array(3) {
219    [0]=>
220    int(%d)
221    [1]=>
222    string(4) "echo"
223    [2]=>
224    int(4)
225  }
226  [8]=>
227  array(3) {
228    [0]=>
229    int(%d)
230    [1]=>
231    string(2) "  "
232    [2]=>
233    int(4)
234  }
235  [9]=>
236  array(3) {
237    [0]=>
238    int(%d)
239    [1]=>
240    string(9) "__CLASS__"
241    [2]=>
242    int(4)
243  }
244  [10]=>
245  string(1) ";"
246  [11]=>
247  array(3) {
248    [0]=>
249    int(%d)
250    [1]=>
251    string(3) "
252  "
253    [2]=>
254    int(%d)
255  }
256  [12]=>
257  array(3) {
258    [0]=>
259    int(%d)
260    [1]=>
261    string(4) "echo"
262    [2]=>
263    int(5)
264  }
265  [13]=>
266  array(3) {
267    [0]=>
268    int(%d)
269    [1]=>
270    string(2) "  "
271    [2]=>
272    int(5)
273  }
274  [14]=>
275  array(3) {
276    [0]=>
277    int(%d)
278    [1]=>
279    string(9) "__TRAIT__"
280    [2]=>
281    int(5)
282  }
283  [15]=>
284  string(1) ";"
285  [16]=>
286  array(3) {
287    [0]=>
288    int(%d)
289    [1]=>
290    string(3) "
291  "
292    [2]=>
293    int(5)
294  }
295  [17]=>
296  array(3) {
297    [0]=>
298    int(%d)
299    [1]=>
300    string(8) "function"
301    [2]=>
302    int(6)
303  }
304  [18]=>
305  array(3) {
306    [0]=>
307    int(%d)
308    [1]=>
309    string(1) " "
310    [2]=>
311    int(6)
312  }
313  [19]=>
314  array(3) {
315    [0]=>
316    int(%d)
317    [1]=>
318    string(10) "myFunction"
319    [2]=>
320    int(6)
321  }
322  [20]=>
323  string(1) "("
324  [21]=>
325  string(1) ")"
326  [22]=>
327  array(3) {
328    [0]=>
329    int(%d)
330    [1]=>
331    string(3) "
332  "
333    [2]=>
334    int(6)
335  }
336  [23]=>
337  string(1) "{"
338  [24]=>
339  array(3) {
340    [0]=>
341    int(%d)
342    [1]=>
343    string(2) "  "
344    [2]=>
345    int(7)
346  }
347  [25]=>
348  array(3) {
349    [0]=>
350    int(%d)
351    [1]=>
352    string(4) "echo"
353    [2]=>
354    int(7)
355  }
356  [26]=>
357  array(3) {
358    [0]=>
359    int(%d)
360    [1]=>
361    string(2) "  "
362    [2]=>
363    int(7)
364  }
365  [27]=>
366  array(3) {
367    [0]=>
368    int(%d)
369    [1]=>
370    string(12) "__FUNCTION__"
371    [2]=>
372    int(7)
373  }
374  [28]=>
375  string(1) ";"
376  [29]=>
377  array(3) {
378    [0]=>
379    int(%d)
380    [1]=>
381    string(1) " "
382    [2]=>
383    int(7)
384  }
385  [30]=>
386  string(1) "}"
387  [31]=>
388  array(3) {
389    [0]=>
390    int(%d)
391    [1]=>
392    string(1) "
393"
394    [2]=>
395    int(7)
396  }
397  [32]=>
398  string(1) "}"
399  [33]=>
400  array(3) {
401    [0]=>
402    int(%d)
403    [1]=>
404    string(1) "
405"
406    [2]=>
407    int(8)
408  }
409  [34]=>
410  array(3) {
411    [0]=>
412    int(%d)
413    [1]=>
414    string(2) "?>"
415    [2]=>
416    int(9)
417  }
418}
419-- with LINE and METHOD --
420array(19) {
421  [0]=>
422  array(3) {
423    [0]=>
424    int(%d)
425    [1]=>
426    string(6) "<?php
427"
428    [2]=>
429    int(1)
430  }
431  [1]=>
432  array(3) {
433    [0]=>
434    int(%d)
435    [1]=>
436    string(2) "  "
437    [2]=>
438    int(2)
439  }
440  [2]=>
441  array(3) {
442    [0]=>
443    int(%d)
444    [1]=>
445    string(2) "$a"
446    [2]=>
447    int(2)
448  }
449  [3]=>
450  array(3) {
451    [0]=>
452    int(%d)
453    [1]=>
454    string(1) " "
455    [2]=>
456    int(2)
457  }
458  [4]=>
459  string(1) "="
460  [5]=>
461  array(3) {
462    [0]=>
463    int(%d)
464    [1]=>
465    string(1) " "
466    [2]=>
467    int(2)
468  }
469  [6]=>
470  array(3) {
471    [0]=>
472    int(%d)
473    [1]=>
474    string(8) "__LINE__"
475    [2]=>
476    int(2)
477  }
478  [7]=>
479  string(1) ";"
480  [8]=>
481  array(3) {
482    [0]=>
483    int(%d)
484    [1]=>
485    string(3) "
486  "
487    [2]=>
488    int(2)
489  }
490  [9]=>
491  array(3) {
492    [0]=>
493    int(%d)
494    [1]=>
495    string(2) "$b"
496    [2]=>
497    int(%d)
498  }
499  [10]=>
500  array(3) {
501    [0]=>
502    int(%d)
503    [1]=>
504    string(1) " "
505    [2]=>
506    int(%d)
507  }
508  [11]=>
509  string(1) "="
510  [12]=>
511  array(3) {
512    [0]=>
513    int(%d)
514    [1]=>
515    string(1) " "
516    [2]=>
517    int(%d)
518  }
519  [13]=>
520  array(3) {
521    [0]=>
522    int(%d)
523    [1]=>
524    string(2) "$b"
525    [2]=>
526    int(%d)
527  }
528  [14]=>
529  string(1) "."
530  [15]=>
531  array(3) {
532    [0]=>
533    int(%d)
534    [1]=>
535    string(10) "__METHOD__"
536    [2]=>
537    int(%d)
538  }
539  [16]=>
540  string(1) ";"
541  [17]=>
542  array(3) {
543    [0]=>
544    int(%d)
545    [1]=>
546    string(1) "
547"
548    [2]=>
549    int(%d)
550  }
551  [18]=>
552  array(3) {
553    [0]=>
554    int(%d)
555    [1]=>
556    string(2) "?>"
557    [2]=>
558    int(4)
559  }
560}
561Done
562