Skip to content

Commit 654734a

Browse files
phpstan-botclaude
authored andcommitted
Allow ClassConstFetch on new to be remembered, add tests for all expression types
Class constants are class-level, not instance-level, so narrowed types from (new Foo())::MY_CONST should still be remembered. Also fix a type error where $expr->class could be a Name (not Expr) for static calls. Added tests covering: method calls, nullsafe method calls, property fetches, nullsafe property fetches, array dim fetches, static calls, static property fetches, class const fetches, and chained expressions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dbdb449 commit 654734a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,6 @@ private function expressionHasNewInChain(Expr $expr): bool
10021002
if (
10031003
$expr instanceof Expr\StaticCall
10041004
|| $expr instanceof Expr\StaticPropertyFetch
1005-
|| $expr instanceof Expr\ClassConstFetch
10061005
) {
10071006
return $expr->class instanceof Expr\New_ || ($expr->class instanceof Expr && $this->expressionHasNewInChain($expr->class));
10081007
}

tests/PHPStan/Analyser/nsrt/bug-8985.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function getEntity(): Entity
4141
{
4242
return new Entity('test');
4343
}
44+
45+
public const MY_CONST = 'const_value';
4446
}
4547

4648
function testMethodCall(): void {
@@ -92,3 +94,9 @@ function testChainedPropertyOnMethodCall(): void {
9294

9395
assertType('string', (new Repository())->getEntity()->value);
9496
}
97+
98+
function testClassConstFetch(): void {
99+
assert((new Repository())::MY_CONST === 'const_value');
100+
101+
assertType("'const_value'", (new Repository())::MY_CONST);
102+
}

0 commit comments

Comments
 (0)