Skip to content

Commit 0cee208

Browse files
committed
Remove self/parent/static restriction for namespace names
This no longer applies as of PHP 8.0.
1 parent 78e08fc commit 0cee208

File tree

3 files changed

+30
-53
lines changed

3 files changed

+30
-53
lines changed

lib/PhpParser/ParserAbstract.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,13 +898,6 @@ protected function checkTryCatch(TryCatch $node) {
898898
}
899899

900900
protected function checkNamespace(Namespace_ $node) {
901-
if ($node->name && $node->name->isSpecialClassName()) {
902-
$this->emitError(new Error(
903-
sprintf('Cannot use \'%s\' as namespace name', $node->name),
904-
$node->name->getAttributes()
905-
));
906-
}
907-
908901
if (null !== $node->stmts) {
909902
foreach ($node->stmts as $stmt) {
910903
if ($stmt instanceof Namespace_) {

test/code/parser/expr/keywordsInNamespacedName.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Keywords in namespaced name
33
<?php
44
namespace fn;
55
namespace fn\use;
6+
namespace self;
7+
namespace parent;
8+
namespace static;
69
fn\use();
710
\fn\use();
811
namespace\fn\use();
@@ -25,6 +28,33 @@ array(
2528
1: use
2629
)
2730
)
31+
stmts: array(
32+
)
33+
)
34+
2: Stmt_Namespace(
35+
name: Name(
36+
parts: array(
37+
0: self
38+
)
39+
)
40+
stmts: array(
41+
)
42+
)
43+
3: Stmt_Namespace(
44+
name: Name(
45+
parts: array(
46+
0: parent
47+
)
48+
)
49+
stmts: array(
50+
)
51+
)
52+
4: Stmt_Namespace(
53+
name: Name(
54+
parts: array(
55+
0: static
56+
)
57+
)
2858
stmts: array(
2959
0: Stmt_Expression(
3060
expr: Expr_FuncCall(

test/code/parser/stmt/namespace/invalidName.test

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
11
Invalid namespace names
22
-----
3-
<?php namespace self;
4-
-----
5-
Cannot use 'self' as namespace name from 1:17 to 1:20
6-
array(
7-
0: Stmt_Namespace(
8-
name: Name(
9-
parts: array(
10-
0: self
11-
)
12-
)
13-
stmts: array(
14-
)
15-
)
16-
)
17-
-----
18-
<?php namespace PARENT;
19-
-----
20-
Cannot use 'PARENT' as namespace name from 1:17 to 1:22
21-
array(
22-
0: Stmt_Namespace(
23-
name: Name(
24-
parts: array(
25-
0: PARENT
26-
)
27-
)
28-
stmts: array(
29-
)
30-
)
31-
)
32-
-----
33-
<?php namespace static;
34-
-----
35-
!!php7
36-
Cannot use 'static' as namespace name from 1:17 to 1:22
37-
array(
38-
0: Stmt_Namespace(
39-
name: Name(
40-
parts: array(
41-
0: static
42-
)
43-
)
44-
stmts: array(
45-
)
46-
)
47-
)
48-
-----
493
<?php use A as self;
504
-----
515
Cannot use A as self because 'self' is a special class name from 1:16 to 1:19

0 commit comments

Comments
 (0)