Annotation of embedaddon/php/ext/tokenizer/tests/token_get_all_variation19.phpt, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>