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