xref: /PHP-5.5/ext/tokenizer/tests/bug54089.phpt (revision 5063a771)
1--TEST--
2Bug #54089 (token_get_all() does not stop after __halt_compiler)
3--SKIPIF--
4<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
5--FILE--
6<?php
7$codes = array(
8	"<?php __halt_compiler",
9	"<?php __halt_compiler(",
10	"<?php __halt_compiler();",
11	"<?php __halt_compiler();ABC",
12	"<?php __halt_compiler\n(\n)\n;ABC",
13	"<?php __halt_compiler\nabc\ndef\nghi ABC",
14);
15foreach ($codes as $code) {
16	$tokens = token_get_all($code);
17	var_dump($tokens);
18
19	$code = '';
20	foreach ($tokens as $t)
21	{
22		$code .= isset($t[1]) ? $t[1] : $t;
23	}
24	var_dump($code);
25}
26
27?>
28--EXPECTF--
29array(2) {
30  [0]=>
31  array(3) {
32    [0]=>
33    int(%d)
34    [1]=>
35    string(6) "<?php "
36    [2]=>
37    int(1)
38  }
39  [1]=>
40  array(3) {
41    [0]=>
42    int(%d)
43    [1]=>
44    string(15) "__halt_compiler"
45    [2]=>
46    int(1)
47  }
48}
49string(21) "<?php __halt_compiler"
50array(3) {
51  [0]=>
52  array(3) {
53    [0]=>
54    int(%d)
55    [1]=>
56    string(6) "<?php "
57    [2]=>
58    int(1)
59  }
60  [1]=>
61  array(3) {
62    [0]=>
63    int(%d)
64    [1]=>
65    string(15) "__halt_compiler"
66    [2]=>
67    int(1)
68  }
69  [2]=>
70  string(1) "("
71}
72string(22) "<?php __halt_compiler("
73array(5) {
74  [0]=>
75  array(3) {
76    [0]=>
77    int(%d)
78    [1]=>
79    string(6) "<?php "
80    [2]=>
81    int(1)
82  }
83  [1]=>
84  array(3) {
85    [0]=>
86    int(%d)
87    [1]=>
88    string(15) "__halt_compiler"
89    [2]=>
90    int(1)
91  }
92  [2]=>
93  string(1) "("
94  [3]=>
95  string(1) ")"
96  [4]=>
97  string(1) ";"
98}
99string(24) "<?php __halt_compiler();"
100array(6) {
101  [0]=>
102  array(3) {
103    [0]=>
104    int(%d)
105    [1]=>
106    string(6) "<?php "
107    [2]=>
108    int(1)
109  }
110  [1]=>
111  array(3) {
112    [0]=>
113    int(%d)
114    [1]=>
115    string(15) "__halt_compiler"
116    [2]=>
117    int(1)
118  }
119  [2]=>
120  string(1) "("
121  [3]=>
122  string(1) ")"
123  [4]=>
124  string(1) ";"
125  [5]=>
126  array(3) {
127    [0]=>
128    int(%d)
129    [1]=>
130    string(3) "ABC"
131    [2]=>
132    int(1)
133  }
134}
135string(27) "<?php __halt_compiler();ABC"
136array(9) {
137  [0]=>
138  array(3) {
139    [0]=>
140    int(%d)
141    [1]=>
142    string(6) "<?php "
143    [2]=>
144    int(1)
145  }
146  [1]=>
147  array(3) {
148    [0]=>
149    int(%d)
150    [1]=>
151    string(15) "__halt_compiler"
152    [2]=>
153    int(1)
154  }
155  [2]=>
156  array(3) {
157    [0]=>
158    int(%d)
159    [1]=>
160    string(1) "
161"
162    [2]=>
163    int(1)
164  }
165  [3]=>
166  string(1) "("
167  [4]=>
168  array(3) {
169    [0]=>
170    int(%d)
171    [1]=>
172    string(1) "
173"
174    [2]=>
175    int(2)
176  }
177  [5]=>
178  string(1) ")"
179  [6]=>
180  array(3) {
181    [0]=>
182    int(%d)
183    [1]=>
184    string(1) "
185"
186    [2]=>
187    int(3)
188  }
189  [7]=>
190  string(1) ";"
191  [8]=>
192  array(3) {
193    [0]=>
194    int(%d)
195    [1]=>
196    string(3) "ABC"
197    [2]=>
198    int(4)
199  }
200}
201string(30) "<?php __halt_compiler
202(
203)
204;ABC"
205array(9) {
206  [0]=>
207  array(3) {
208    [0]=>
209    int(%d)
210    [1]=>
211    string(6) "<?php "
212    [2]=>
213    int(1)
214  }
215  [1]=>
216  array(3) {
217    [0]=>
218    int(%d)
219    [1]=>
220    string(15) "__halt_compiler"
221    [2]=>
222    int(1)
223  }
224  [2]=>
225  array(3) {
226    [0]=>
227    int(%d)
228    [1]=>
229    string(1) "
230"
231    [2]=>
232    int(1)
233  }
234  [3]=>
235  array(3) {
236    [0]=>
237    int(%d)
238    [1]=>
239    string(3) "abc"
240    [2]=>
241    int(2)
242  }
243  [4]=>
244  array(3) {
245    [0]=>
246    int(%d)
247    [1]=>
248    string(1) "
249"
250    [2]=>
251    int(2)
252  }
253  [5]=>
254  array(3) {
255    [0]=>
256    int(%d)
257    [1]=>
258    string(3) "def"
259    [2]=>
260    int(3)
261  }
262  [6]=>
263  array(3) {
264    [0]=>
265    int(%d)
266    [1]=>
267    string(1) "
268"
269    [2]=>
270    int(3)
271  }
272  [7]=>
273  array(3) {
274    [0]=>
275    int(%d)
276    [1]=>
277    string(3) "ghi"
278    [2]=>
279    int(4)
280  }
281  [8]=>
282  array(3) {
283    [0]=>
284    int(%d)
285    [1]=>
286    string(4) " ABC"
287    [2]=>
288    int(4)
289  }
290}
291string(37) "<?php __halt_compiler
292abc
293def
294ghi ABC"
295