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