]> granicus.if.org Git - php/commitdiff
Fixed bug #54089 (token_get_all() does not stop after __halt_compiler).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 28 Feb 2011 15:18:27 +0000 (15:18 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 28 Feb 2011 15:18:27 +0000 (15:18 +0000)
ext/tokenizer/tests/bug54089.phpt [new file with mode: 0644]
ext/tokenizer/tests/token_get_all_variation16.phpt
ext/tokenizer/tokenizer.c

diff --git a/ext/tokenizer/tests/bug54089.phpt b/ext/tokenizer/tests/bug54089.phpt
new file mode 100644 (file)
index 0000000..e1f6d79
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Bug #54089 (token_get_all() does not stop after __halt_compiler)
+--SKIPIF--
+<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
+--FILE--
+<?php
+$code = "<?php __halt_compiler();\x01?>\x02";
+$tokens = token_get_all($code);
+
+var_dump($tokens);
+
+$code = '';
+foreach ($tokens as $t)
+{
+       $code .= isset($t[1]) ? $t[1] : $t;
+}
+var_dump($code);
+?>
+--EXPECTF--
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(%d)
+    [1]=>
+    string(6) "<?php "
+    [2]=>
+    int(1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(%d)
+    [1]=>
+    string(15) "__halt_compiler"
+    [2]=>
+    int(1)
+  }
+}
+string(21) "<?php __halt_compiler"
index 2422d30266d9d05878379c5f0ad5cf5596925955..4ae694e7419a17f715ecc8b43c8d5a0b75aac02a 100644 (file)
@@ -55,7 +55,7 @@ echo "Done"
 ?>
 --EXPECTF--
 *** Testing token_get_all() : with different function constructs ***
-array(142) {
+array(135) {
   [0]=>
   array(3) {
     [0]=>
@@ -114,11 +114,11 @@ array(142) {
   [9]=>
   array(3) {
     [0]=>
-    int(262)
+    int(%d)
     [1]=>
     string(7) "include"
     [2]=>
-    int(%d)
+    int(3)
   }
   [10]=>
   string(1) "("
@@ -129,7 +129,7 @@ array(142) {
     [1]=>
     string(13) ""addfile.php""
     [2]=>
-    int(%d)
+    int(3)
   }
   [12]=>
   string(1) ")"
@@ -143,12 +143,12 @@ array(142) {
     string(1) "
 "
     [2]=>
-    int(%d)
+    int(3)
   }
   [15]=>
   array(3) {
     [0]=>
-    int(259)
+    int(%d)
     [1]=>
     string(7) "require"
     [2]=>
@@ -590,7 +590,7 @@ array(142) {
   [79]=>
   array(3) {
     [0]=>
-    int(267)
+    int(%d)
     [1]=>
     string(3) ">>="
     [2]=>
@@ -659,7 +659,7 @@ array(142) {
   [88]=>
   array(3) {
     [0]=>
-    int(285)
+    int(%d)
     [1]=>
     string(2) "<="
     [2]=>
@@ -738,7 +738,7 @@ array(142) {
   [98]=>
   array(3) {
     [0]=>
-    int(266)
+    int(%d)
     [1]=>
     string(5) "print"
     [2]=>
@@ -889,7 +889,7 @@ array(142) {
   [123]=>
   array(3) {
     [0]=>
-    int(279)
+    int(%d)
     [1]=>
     string(2) "&&"
     [2]=>
@@ -960,42 +960,5 @@ array(142) {
     [2]=>
     int(26)
   }
-  [135]=>
-  string(1) "("
-  [136]=>
-  string(1) ")"
-  [137]=>
-  string(1) ";"
-  [138]=>
-  array(3) {
-    [0]=>
-    int(%d)
-    [1]=>
-    string(1) "
-"
-    [2]=>
-    int(26)
-  }
-  [139]=>
-  string(1) "}"
-  [140]=>
-  array(3) {
-    [0]=>
-    int(%d)
-    [1]=>
-    string(1) "
-"
-    [2]=>
-    int(27)
-  }
-  [141]=>
-  array(3) {
-    [0]=>
-    int(%d)
-    [1]=>
-    string(2) "?>"
-    [2]=>
-    int(28)
-  }
 }
 Done
index bab549bad7fdfcfc896f415fe6adcf59d6ebb673..add3168f7c0c55529a2f783473af6eb1824722c1 100644 (file)
@@ -151,6 +151,10 @@ static void tokenize(zval *return_value TSRMLS_DC)
                ZVAL_NULL(&token);
 
                token_line = CG(zend_lineno);
+
+               if (token_type == T_HALT_COMPILER) {
+                       break;
+               }
        }
 }