Skip to content

Commit 47f3fa9

Browse files
authored
Merge pull request #100 from theofidry/bugfix/new-static
Fix usage of special keywords in a new statement. Closes #99
2 parents 227a4fd + fe42953 commit 47f3fa9

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

specs/special-keywords/self-static-parent-method.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ public static function test() {
4444
static::who();
4545
}
4646
47-
public function getName(): string
48-
{
47+
public function getName(): string {
4948
return $this->name;
5049
}
50+
51+
public function create(): self {
52+
return new static();
53+
return new self();
54+
return parent::create();
55+
}
5156
}
5257
5358
class B extends A {
@@ -86,6 +91,12 @@ public function getName() : string
8691
{
8792
return $this->name;
8893
}
94+
public function create() : self
95+
{
96+
return new static();
97+
return new self();
98+
return parent::create();
99+
}
89100
}
90101
class B extends \A
91102
{
@@ -129,10 +140,15 @@ public static function test() {
129140
static::who();
130141
}
131142
132-
public function getName(): string
133-
{
143+
public function getName(): string {
134144
return $this->name;
135145
}
146+
147+
public function create(): self {
148+
return new static();
149+
return new self();
150+
return parent::create();
151+
}
136152
}
137153
138154
class B extends A {
@@ -175,6 +191,12 @@ public function getName() : string
175191
{
176192
return $this->name;
177193
}
194+
public function create() : self
195+
{
196+
return new static();
197+
return new self();
198+
return parent::create();
199+
}
178200
}
179201
class B extends \Humbug\Foo\A
180202
{

src/NodeVisitor/NameStmtPrefixer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ private function prefixName(Name $name): Node
9999
return $name;
100100
}
101101

102-
if (($parentNode instanceof FuncCall || $parentNode instanceof StaticCall || $parentNode instanceof ClassConstFetch)
102+
if ((
103+
$parentNode instanceof FuncCall
104+
|| $parentNode instanceof StaticCall
105+
|| $parentNode instanceof ClassConstFetch
106+
|| $parentNode instanceof New_
107+
)
103108
&& in_array((string) $name, self::PHP_FUNCTION_KEYWORDS)
104109
) {
105110
return $name;

0 commit comments

Comments
 (0)