Allow nop statements before namespace declaration

This commit is contained in:
Nikita Popov 2016-04-16 21:39:49 +02:00
parent f8a40b3f24
commit 4c7ad7e194
3 changed files with 27 additions and 3 deletions

View File

@ -463,8 +463,10 @@ abstract class ParserAbstract implements Parser
continue;
}
/* declare() and __halt_compiler() can be used before a namespace declaration */
if ($stmt instanceof Node\Stmt\Declare_ || $stmt instanceof Node\Stmt\HaltCompiler) {
/* declare(), __halt_compiler() and nops can be used before a namespace declaration */
if ($stmt instanceof Node\Stmt\Declare_
|| $stmt instanceof Node\Stmt\HaltCompiler
|| $stmt instanceof Node\Stmt\Nop) {
continue;
}

View File

@ -25,7 +25,7 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase
);
// parse sections
$parts = explode("\n-----\n", $fileContents);
$parts = preg_split("/\n-----(?:\n|$)/", $fileContents);
// first part is the name
$name = array_shift($parts) . ' (' . $fileName . ')';

View File

@ -33,4 +33,26 @@ array(
2: Stmt_HaltCompiler(
remaining: Hi!
)
)
-----
<?php
/* Comment */
;
namespace Foo;
-----
array(
0: Stmt_Nop(
comments: array(
0: /* Comment */
)
)
1: Stmt_Namespace(
name: Name(
parts: array(
0: Foo
)
)
stmts: array(
)
)
)