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