Annotation of embedaddon/php/ext/tokenizer/tests/token_get_all_variation19.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Reconstructing a script using token_get_all()
1.1.1.2 ! misho 3: --SKIPIF--
! 4: <?php if (!extension_loaded("tokenizer")) print "skip"; ?>
1.1 misho 5: --FILE--
6: <?php
7:
8: $phpstr = '
9: <?php
10:
11: // A php script to test token_get_all()
12:
13: /* a different
14: type of
15: comment */
16:
17: // a class
18: class TestClass {
19: public function foo() {
20: echo "Called foo()\n";
21: }
22: }
23:
24: $a = new TestClass();
25: $a->foo();
26:
27: for ($i = 0; $i < 10; $i++) {
28: echo "Loop iteration $i\n";
29: }
30:
31: ?>';
32:
33: $token_array = token_get_all($phpstr);
34:
35: $script = "";
36: // reconstruct a script (without open/close tags) from the token array
37: foreach ($token_array as $token) {
38: if (is_array($token)) {
39: if (strncmp($token[1], '<?php', 5) == 0) {
40: continue;
41: }
42: if (strncmp($token[1], '?>', 2) == 0) {
43: continue;
44: }
45: $script .= $token[1];
46: } else {
47: $script .= $token;
48: }
49: }
50:
51: var_dump($script);
52:
53: eval($script);
54:
55: ?>
56: --EXPECT--
57: string(259) "
58:
59: // A php script to test token_get_all()
60:
61: /* a different
62: type of
63: comment */
64:
65: // a class
66: class TestClass {
67: public function foo() {
68: echo "Called foo()\n";
69: }
70: }
71:
72: $a = new TestClass();
73: $a->foo();
74:
75: for ($i = 0; $i < 10; $i++) {
76: echo "Loop iteration $i\n";
77: }
78:
79: "
80: Called foo()
81: Loop iteration 0
82: Loop iteration 1
83: Loop iteration 2
84: Loop iteration 3
85: Loop iteration 4
86: Loop iteration 5
87: Loop iteration 6
88: Loop iteration 7
89: Loop iteration 8
90: Loop iteration 9
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>