mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 20:14:46 +01:00
Fix __halt_compiler() usage in namespace
This fixes the only left bug that was reported by parsing the PHP testsuite :)
This commit is contained in:
parent
8bdb478785
commit
df691065a6
@ -132,7 +132,7 @@ class PHPParser_Lexer
|
||||
$this->pos = count($this->tokens);
|
||||
|
||||
// return with (); removed
|
||||
return substr($textAfter, strlen($matches[0]));
|
||||
return (string) substr($textAfter, strlen($matches[0])); // (string) converts false to ''
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,17 +101,20 @@ class PHPParser_Node_Stmt_Namespace extends PHPParser_Node_Stmt
|
||||
|
||||
// iterate over all following namespaces
|
||||
for ($i = 0, $c = count($nsOffsets); $i < $c; ++$i) {
|
||||
$nsStmt = $stmts[$nsOffsets[$i]];
|
||||
$newStmts[] = $nsStmt = $stmts[$nsOffsets[$i]];
|
||||
|
||||
// the last namespace takes all statements after it
|
||||
if ($c === $i + 1) {
|
||||
$nsStmt->stmts = array_slice($stmts, $nsOffsets[$i] + 1);
|
||||
|
||||
// if the last statement is __halt_compiler() put it outside the namespace
|
||||
if (end($nsStmt->stmts) instanceof PHPParser_Node_Stmt_HaltCompiler) {
|
||||
$newStmts[] = array_pop($nsStmt->stmts);
|
||||
}
|
||||
// and all the others take all statements between the current and the following one
|
||||
} else {
|
||||
$nsStmt->stmts = array_slice($stmts, $nsOffsets[$i] + 1, $nsOffsets[$i + 1] - $nsOffsets[$i] - 1);
|
||||
}
|
||||
|
||||
$newStmts[] = $nsStmt;
|
||||
}
|
||||
|
||||
return $newStmts;
|
||||
|
@ -28,4 +28,28 @@ array(
|
||||
1: Stmt_HaltCompiler(
|
||||
remaining: Hallo World!
|
||||
)
|
||||
)
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace A;
|
||||
$a;
|
||||
__halt_compiler();
|
||||
-----
|
||||
array(
|
||||
0: Stmt_Namespace(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: A
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
0: Expr_Variable(
|
||||
name: a
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_HaltCompiler(
|
||||
remaining:
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user