1--TEST--
2Reconstructing a script using token_get_all()
3--SKIPIF--
4<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
5--FILE--
6<?php
7
8$phpstr = '
9<?php
10
11// A php script to test token_get_all()
12
13/* a different
14type of
15comment */
16
17// a class
18class TestClass {
19    public function foo() {
20        echo "Called foo()\n";
21    }
22}
23
24$a = new TestClass();
25$a->foo();
26
27for ($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
37foreach ($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
51var_dump($script);
52
53eval($script);
54
55?>
56--EXPECT--
57string(274) "
58
59// A php script to test token_get_all()
60
61/* a different
62type of
63comment */
64
65// a class
66class TestClass {
67    public function foo() {
68        echo "Called foo()\n";
69    }
70}
71
72$a = new TestClass();
73$a->foo();
74
75for ($i = 0; $i < 10; $i++) {
76    echo "Loop iteration $i\n";
77}
78
79"
80Called foo()
81Loop iteration 0
82Loop iteration 1
83Loop iteration 2
84Loop iteration 3
85Loop iteration 4
86Loop iteration 5
87Loop iteration 6
88Loop iteration 7
89Loop iteration 8
90Loop iteration 9
91