1--TEST--
2Test token_get_all() function : usage variations - with constant tokens
3--SKIPIF--
4<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
5--FILE--
6<?php
7/*
8 * Using different types of constants in 'source' string to check them for token
9 * integer const - T_LNUMBER(305)
10 * float/double/real const - T_DNUMBER(306)
11 * string cosnt - T_CONSTANT_ESCAPED_STRING(315)
12 * bool const (no tokens specified) - T_UNKNOWN(307)
13 * null const (no tokens specified) - T_UNKNOWN(307)
14*/
15
16echo "*** Testing token_get_all() :  'source' string with different constants ***\n";
17
18$a = 1;
19$b = 0;
20
21$source = array (
22  // int const
23  '<?php $a = 1 + 034; $b = $a + 0x3F; ?>',
24
25  // float const
26  '<?php $a = 0.23E-2 + 0.43e2 + 0.5; ?>',
27
28  // string const
29  '<?php $a = "hello ".\'world\'; ?>',
30
31  // bool const
32  "<?php \$a = (\$b)? true : false; ?>",
33  "<?php \$b = (\$a)? FALSE : TRUE; ?>",
34
35  // null const
36  '<?php $b = null | NULL; ?>'
37);
38for($count = 0; $count < count($source); $count++) {
39  echo "-- Iteration ".($count + 1)." --\n";
40  var_dump( token_get_all($source[$count]));
41}
42
43echo "Done"
44?>
45--EXPECTF--
46*** Testing token_get_all() :  'source' string with different constants ***
47-- Iteration 1 --
48array(24) {
49  [0]=>
50  array(3) {
51    [0]=>
52    int(%d)
53    [1]=>
54    string(6) "<?php "
55    [2]=>
56    int(1)
57  }
58  [1]=>
59  array(3) {
60    [0]=>
61    int(%d)
62    [1]=>
63    string(2) "$a"
64    [2]=>
65    int(1)
66  }
67  [2]=>
68  array(3) {
69    [0]=>
70    int(%d)
71    [1]=>
72    string(1) " "
73    [2]=>
74    int(1)
75  }
76  [3]=>
77  string(1) "="
78  [4]=>
79  array(3) {
80    [0]=>
81    int(%d)
82    [1]=>
83    string(1) " "
84    [2]=>
85    int(1)
86  }
87  [5]=>
88  array(3) {
89    [0]=>
90    int(%d)
91    [1]=>
92    string(1) "1"
93    [2]=>
94    int(1)
95  }
96  [6]=>
97  array(3) {
98    [0]=>
99    int(%d)
100    [1]=>
101    string(1) " "
102    [2]=>
103    int(1)
104  }
105  [7]=>
106  string(1) "+"
107  [8]=>
108  array(3) {
109    [0]=>
110    int(%d)
111    [1]=>
112    string(1) " "
113    [2]=>
114    int(1)
115  }
116  [9]=>
117  array(3) {
118    [0]=>
119    int(%d)
120    [1]=>
121    string(3) "034"
122    [2]=>
123    int(1)
124  }
125  [10]=>
126  string(1) ";"
127  [11]=>
128  array(3) {
129    [0]=>
130    int(%d)
131    [1]=>
132    string(1) " "
133    [2]=>
134    int(1)
135  }
136  [12]=>
137  array(3) {
138    [0]=>
139    int(%d)
140    [1]=>
141    string(2) "$b"
142    [2]=>
143    int(1)
144  }
145  [13]=>
146  array(3) {
147    [0]=>
148    int(%d)
149    [1]=>
150    string(1) " "
151    [2]=>
152    int(1)
153  }
154  [14]=>
155  string(1) "="
156  [15]=>
157  array(3) {
158    [0]=>
159    int(%d)
160    [1]=>
161    string(1) " "
162    [2]=>
163    int(1)
164  }
165  [16]=>
166  array(3) {
167    [0]=>
168    int(%d)
169    [1]=>
170    string(2) "$a"
171    [2]=>
172    int(1)
173  }
174  [17]=>
175  array(3) {
176    [0]=>
177    int(%d)
178    [1]=>
179    string(1) " "
180    [2]=>
181    int(1)
182  }
183  [18]=>
184  string(1) "+"
185  [19]=>
186  array(3) {
187    [0]=>
188    int(%d)
189    [1]=>
190    string(1) " "
191    [2]=>
192    int(1)
193  }
194  [20]=>
195  array(3) {
196    [0]=>
197    int(%d)
198    [1]=>
199    string(4) "0x3F"
200    [2]=>
201    int(1)
202  }
203  [21]=>
204  string(1) ";"
205  [22]=>
206  array(3) {
207    [0]=>
208    int(%d)
209    [1]=>
210    string(1) " "
211    [2]=>
212    int(1)
213  }
214  [23]=>
215  array(3) {
216    [0]=>
217    int(%d)
218    [1]=>
219    string(2) "?>"
220    [2]=>
221    int(1)
222  }
223}
224-- Iteration 2 --
225array(17) {
226  [0]=>
227  array(3) {
228    [0]=>
229    int(%d)
230    [1]=>
231    string(6) "<?php "
232    [2]=>
233    int(1)
234  }
235  [1]=>
236  array(3) {
237    [0]=>
238    int(%d)
239    [1]=>
240    string(2) "$a"
241    [2]=>
242    int(1)
243  }
244  [2]=>
245  array(3) {
246    [0]=>
247    int(%d)
248    [1]=>
249    string(1) " "
250    [2]=>
251    int(1)
252  }
253  [3]=>
254  string(1) "="
255  [4]=>
256  array(3) {
257    [0]=>
258    int(%d)
259    [1]=>
260    string(1) " "
261    [2]=>
262    int(1)
263  }
264  [5]=>
265  array(3) {
266    [0]=>
267    int(%d)
268    [1]=>
269    string(7) "0.23E-2"
270    [2]=>
271    int(1)
272  }
273  [6]=>
274  array(3) {
275    [0]=>
276    int(%d)
277    [1]=>
278    string(1) " "
279    [2]=>
280    int(1)
281  }
282  [7]=>
283  string(1) "+"
284  [8]=>
285  array(3) {
286    [0]=>
287    int(%d)
288    [1]=>
289    string(1) " "
290    [2]=>
291    int(1)
292  }
293  [9]=>
294  array(3) {
295    [0]=>
296    int(%d)
297    [1]=>
298    string(6) "0.43e2"
299    [2]=>
300    int(1)
301  }
302  [10]=>
303  array(3) {
304    [0]=>
305    int(%d)
306    [1]=>
307    string(1) " "
308    [2]=>
309    int(1)
310  }
311  [11]=>
312  string(1) "+"
313  [12]=>
314  array(3) {
315    [0]=>
316    int(%d)
317    [1]=>
318    string(1) " "
319    [2]=>
320    int(1)
321  }
322  [13]=>
323  array(3) {
324    [0]=>
325    int(%d)
326    [1]=>
327    string(3) "0.5"
328    [2]=>
329    int(1)
330  }
331  [14]=>
332  string(1) ";"
333  [15]=>
334  array(3) {
335    [0]=>
336    int(%d)
337    [1]=>
338    string(1) " "
339    [2]=>
340    int(1)
341  }
342  [16]=>
343  array(3) {
344    [0]=>
345    int(%d)
346    [1]=>
347    string(2) "?>"
348    [2]=>
349    int(1)
350  }
351}
352-- Iteration 3 --
353array(11) {
354  [0]=>
355  array(3) {
356    [0]=>
357    int(%d)
358    [1]=>
359    string(6) "<?php "
360    [2]=>
361    int(1)
362  }
363  [1]=>
364  array(3) {
365    [0]=>
366    int(%d)
367    [1]=>
368    string(2) "$a"
369    [2]=>
370    int(1)
371  }
372  [2]=>
373  array(3) {
374    [0]=>
375    int(%d)
376    [1]=>
377    string(1) " "
378    [2]=>
379    int(1)
380  }
381  [3]=>
382  string(1) "="
383  [4]=>
384  array(3) {
385    [0]=>
386    int(%d)
387    [1]=>
388    string(1) " "
389    [2]=>
390    int(1)
391  }
392  [5]=>
393  array(3) {
394    [0]=>
395    int(%d)
396    [1]=>
397    string(8) ""hello ""
398    [2]=>
399    int(1)
400  }
401  [6]=>
402  string(1) "."
403  [7]=>
404  array(3) {
405    [0]=>
406    int(%d)
407    [1]=>
408    string(7) "'world'"
409    [2]=>
410    int(1)
411  }
412  [8]=>
413  string(1) ";"
414  [9]=>
415  array(3) {
416    [0]=>
417    int(%d)
418    [1]=>
419    string(1) " "
420    [2]=>
421    int(1)
422  }
423  [10]=>
424  array(3) {
425    [0]=>
426    int(%d)
427    [1]=>
428    string(2) "?>"
429    [2]=>
430    int(1)
431  }
432}
433-- Iteration 4 --
434array(18) {
435  [0]=>
436  array(3) {
437    [0]=>
438    int(%d)
439    [1]=>
440    string(6) "<?php "
441    [2]=>
442    int(1)
443  }
444  [1]=>
445  array(3) {
446    [0]=>
447    int(%d)
448    [1]=>
449    string(2) "$a"
450    [2]=>
451    int(1)
452  }
453  [2]=>
454  array(3) {
455    [0]=>
456    int(%d)
457    [1]=>
458    string(1) " "
459    [2]=>
460    int(1)
461  }
462  [3]=>
463  string(1) "="
464  [4]=>
465  array(3) {
466    [0]=>
467    int(%d)
468    [1]=>
469    string(1) " "
470    [2]=>
471    int(1)
472  }
473  [5]=>
474  string(1) "("
475  [6]=>
476  array(3) {
477    [0]=>
478    int(%d)
479    [1]=>
480    string(2) "$b"
481    [2]=>
482    int(1)
483  }
484  [7]=>
485  string(1) ")"
486  [8]=>
487  string(1) "?"
488  [9]=>
489  array(3) {
490    [0]=>
491    int(%d)
492    [1]=>
493    string(1) " "
494    [2]=>
495    int(1)
496  }
497  [10]=>
498  array(3) {
499    [0]=>
500    int(%d)
501    [1]=>
502    string(4) "true"
503    [2]=>
504    int(1)
505  }
506  [11]=>
507  array(3) {
508    [0]=>
509    int(%d)
510    [1]=>
511    string(1) " "
512    [2]=>
513    int(1)
514  }
515  [12]=>
516  string(1) ":"
517  [13]=>
518  array(3) {
519    [0]=>
520    int(%d)
521    [1]=>
522    string(1) " "
523    [2]=>
524    int(1)
525  }
526  [14]=>
527  array(3) {
528    [0]=>
529    int(%d)
530    [1]=>
531    string(5) "false"
532    [2]=>
533    int(1)
534  }
535  [15]=>
536  string(1) ";"
537  [16]=>
538  array(3) {
539    [0]=>
540    int(%d)
541    [1]=>
542    string(1) " "
543    [2]=>
544    int(1)
545  }
546  [17]=>
547  array(3) {
548    [0]=>
549    int(%d)
550    [1]=>
551    string(2) "?>"
552    [2]=>
553    int(1)
554  }
555}
556-- Iteration 5 --
557array(18) {
558  [0]=>
559  array(3) {
560    [0]=>
561    int(%d)
562    [1]=>
563    string(6) "<?php "
564    [2]=>
565    int(1)
566  }
567  [1]=>
568  array(3) {
569    [0]=>
570    int(%d)
571    [1]=>
572    string(2) "$b"
573    [2]=>
574    int(1)
575  }
576  [2]=>
577  array(3) {
578    [0]=>
579    int(%d)
580    [1]=>
581    string(1) " "
582    [2]=>
583    int(1)
584  }
585  [3]=>
586  string(1) "="
587  [4]=>
588  array(3) {
589    [0]=>
590    int(%d)
591    [1]=>
592    string(1) " "
593    [2]=>
594    int(1)
595  }
596  [5]=>
597  string(1) "("
598  [6]=>
599  array(3) {
600    [0]=>
601    int(%d)
602    [1]=>
603    string(2) "$a"
604    [2]=>
605    int(1)
606  }
607  [7]=>
608  string(1) ")"
609  [8]=>
610  string(1) "?"
611  [9]=>
612  array(3) {
613    [0]=>
614    int(%d)
615    [1]=>
616    string(1) " "
617    [2]=>
618    int(1)
619  }
620  [10]=>
621  array(3) {
622    [0]=>
623    int(%d)
624    [1]=>
625    string(5) "FALSE"
626    [2]=>
627    int(1)
628  }
629  [11]=>
630  array(3) {
631    [0]=>
632    int(%d)
633    [1]=>
634    string(1) " "
635    [2]=>
636    int(1)
637  }
638  [12]=>
639  string(1) ":"
640  [13]=>
641  array(3) {
642    [0]=>
643    int(%d)
644    [1]=>
645    string(1) " "
646    [2]=>
647    int(1)
648  }
649  [14]=>
650  array(3) {
651    [0]=>
652    int(%d)
653    [1]=>
654    string(4) "TRUE"
655    [2]=>
656    int(1)
657  }
658  [15]=>
659  string(1) ";"
660  [16]=>
661  array(3) {
662    [0]=>
663    int(%d)
664    [1]=>
665    string(1) " "
666    [2]=>
667    int(1)
668  }
669  [17]=>
670  array(3) {
671    [0]=>
672    int(%d)
673    [1]=>
674    string(2) "?>"
675    [2]=>
676    int(1)
677  }
678}
679-- Iteration 6 --
680array(13) {
681  [0]=>
682  array(3) {
683    [0]=>
684    int(%d)
685    [1]=>
686    string(6) "<?php "
687    [2]=>
688    int(1)
689  }
690  [1]=>
691  array(3) {
692    [0]=>
693    int(%d)
694    [1]=>
695    string(2) "$b"
696    [2]=>
697    int(1)
698  }
699  [2]=>
700  array(3) {
701    [0]=>
702    int(%d)
703    [1]=>
704    string(1) " "
705    [2]=>
706    int(1)
707  }
708  [3]=>
709  string(1) "="
710  [4]=>
711  array(3) {
712    [0]=>
713    int(%d)
714    [1]=>
715    string(1) " "
716    [2]=>
717    int(1)
718  }
719  [5]=>
720  array(3) {
721    [0]=>
722    int(%d)
723    [1]=>
724    string(4) "null"
725    [2]=>
726    int(1)
727  }
728  [6]=>
729  array(3) {
730    [0]=>
731    int(%d)
732    [1]=>
733    string(1) " "
734    [2]=>
735    int(1)
736  }
737  [7]=>
738  string(1) "|"
739  [8]=>
740  array(3) {
741    [0]=>
742    int(%d)
743    [1]=>
744    string(1) " "
745    [2]=>
746    int(1)
747  }
748  [9]=>
749  array(3) {
750    [0]=>
751    int(%d)
752    [1]=>
753    string(4) "NULL"
754    [2]=>
755    int(1)
756  }
757  [10]=>
758  string(1) ";"
759  [11]=>
760  array(3) {
761    [0]=>
762    int(%d)
763    [1]=>
764    string(1) " "
765    [2]=>
766    int(1)
767  }
768  [12]=>
769  array(3) {
770    [0]=>
771    int(%d)
772    [1]=>
773    string(2) "?>"
774    [2]=>
775    int(1)
776  }
777}
778Done
779