Skip to content

Commit 09a1cef

Browse files
phpstan-botclaude
andcommitted
Also warn about ?? on $this->prop when property has a default value
For $this->prop access on native-typed properties with a default value, the property is always initialized so ?? on non-nullable types is useless. Only skip the warning for $this->prop when the property has no default value (could be uninitialized). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bfa4708 commit 09a1cef

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

src/Rules/IssetCheck.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,6 @@ static function (Type $type) use ($typeMessageCallback): ?string {
182182
}
183183

184184
if (!$scope->hasExpressionType($expr)->yes()) {
185-
if (
186-
$expr instanceof Node\Expr\PropertyFetch
187-
&& $expr->var instanceof Expr\Variable
188-
&& $expr->var->name === 'this'
189-
) {
190-
return $this->checkUndefined($expr->var, $scope, $operatorDescription, $identifier);
191-
}
192-
193185
if ($expr instanceof Node\Expr\StaticPropertyFetch) {
194186
if ($expr->class instanceof Expr) {
195187
return $this->checkUndefined($expr->class, $scope, $operatorDescription, $identifier);

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ public function testBug13921(): void
373373
public function testBug14393(): void
374374
{
375375
$this->analyse([__DIR__ . '/data/bug-14393.php'], [
376+
[
377+
'Property Bug14393\MyClass::$i (int) on left side of ?? is not nullable.',
378+
11,
379+
],
376380
[
377381
'Property Bug14393\MyClass::$i (int) on left side of ?? is not nullable.',
378382
27,

0 commit comments

Comments
 (0)