diff --git a/lib/PHPParser/Lexer.php b/lib/PHPParser/Lexer.php index d569469..d214c34 100644 --- a/lib/PHPParser/Lexer.php +++ b/lib/PHPParser/Lexer.php @@ -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 '' } /** diff --git a/lib/PHPParser/Node/Stmt/Namespace.php b/lib/PHPParser/Node/Stmt/Namespace.php index 3e4e500..299581b 100644 --- a/lib/PHPParser/Node/Stmt/Namespace.php +++ b/lib/PHPParser/Node/Stmt/Namespace.php @@ -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; diff --git a/test/code/stmt/haltCompiler.test b/test/code/stmt/haltCompiler.test index 3ef87c3..67133ba 100644 --- a/test/code/stmt/haltCompiler.test +++ b/test/code/stmt/haltCompiler.test @@ -28,4 +28,28 @@ array( 1: Stmt_HaltCompiler( remaining: Hallo World! ) +) +----- +