1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Remove self/parent/static restriction for namespace names

This no longer applies as of PHP 8.0.
This commit is contained in:
Nikita Popov 2020-08-09 21:21:22 +02:00
parent 78e08fc178
commit 0cee2088ea
3 changed files with 30 additions and 53 deletions

View File

@ -898,13 +898,6 @@ abstract class ParserAbstract implements Parser
} }
protected function checkNamespace(Namespace_ $node) { protected function checkNamespace(Namespace_ $node) {
if ($node->name && $node->name->isSpecialClassName()) {
$this->emitError(new Error(
sprintf('Cannot use \'%s\' as namespace name', $node->name),
$node->name->getAttributes()
));
}
if (null !== $node->stmts) { if (null !== $node->stmts) {
foreach ($node->stmts as $stmt) { foreach ($node->stmts as $stmt) {
if ($stmt instanceof Namespace_) { if ($stmt instanceof Namespace_) {

View File

@ -3,6 +3,9 @@ Keywords in namespaced name
<?php <?php
namespace fn; namespace fn;
namespace fn\use; namespace fn\use;
namespace self;
namespace parent;
namespace static;
fn\use(); fn\use();
\fn\use(); \fn\use();
namespace\fn\use(); namespace\fn\use();
@ -25,6 +28,33 @@ array(
1: use 1: use
) )
) )
stmts: array(
)
)
2: Stmt_Namespace(
name: Name(
parts: array(
0: self
)
)
stmts: array(
)
)
3: Stmt_Namespace(
name: Name(
parts: array(
0: parent
)
)
stmts: array(
)
)
4: Stmt_Namespace(
name: Name(
parts: array(
0: static
)
)
stmts: array( stmts: array(
0: Stmt_Expression( 0: Stmt_Expression(
expr: Expr_FuncCall( expr: Expr_FuncCall(

View File

@ -1,51 +1,5 @@
Invalid namespace names Invalid namespace names
----- -----
<?php namespace self;
-----
Cannot use 'self' as namespace name from 1:17 to 1:20
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: self
)
)
stmts: array(
)
)
)
-----
<?php namespace PARENT;
-----
Cannot use 'PARENT' as namespace name from 1:17 to 1:22
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: PARENT
)
)
stmts: array(
)
)
)
-----
<?php namespace static;
-----
!!php7
Cannot use 'static' as namespace name from 1:17 to 1:22
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: static
)
)
stmts: array(
)
)
)
-----
<?php use A as self; <?php use A as self;
----- -----
Cannot use A as self because 'self' is a special class name from 1:16 to 1:19 Cannot use A as self because 'self' is a special class name from 1:16 to 1:19