Skip to content

Commit f5a8d08

Browse files
committed
fix name resolving
1 parent 7b85290 commit f5a8d08

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4382,7 +4382,10 @@ private function shouldInvalidateExpression(string $exprStringToInvalidate, Expr
43824382
if (
43834383
$exprStringToInvalidate === '$this'
43844384
&& $node instanceof Name
4385-
&& in_array($node->toLowerString(), ['self', 'static', 'parent'], true)
4385+
&& (
4386+
in_array($node->toLowerString(), ['self', 'static', 'parent'], true)
4387+
|| $this->getClassReflection()->is($this->resolveName($node))
4388+
)
43864389
) {
43874390
return true;
43884391
}

tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ public function testBug8523b(): void
6565
$this->analyse([__DIR__ . '/data/bug-8523b.php'], []);
6666
}
6767

68+
public function testBug8523c(): void
69+
{
70+
$this->analyse([__DIR__ . '/data/bug-8523c.php'], []);
71+
}
72+
6873
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8523c;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public static ?HelloWorld $instance = null;
10+
11+
public function save(): void {
12+
HelloWorld::$instance = new HelloWorld();
13+
14+
$callback = static function(): void {
15+
HelloWorld::$instance = null;
16+
};
17+
18+
$callback();
19+
20+
var_dump(HelloWorld::$instance);
21+
22+
HelloWorld::$instance?->save();
23+
}
24+
}
25+
26+
(new HelloWorld())->save();

0 commit comments

Comments
 (0)