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