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