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