Skip to content

Commit db70c6c

Browse files
phpstan-botclaude
andcommitted
Add tests proving isset() still reports for properties with default values
Properties with default values (e.g. `private int $bar = 1;`) are handled by `hasDefaultValue()` in IssetCheck, not by PropertyInitializationExpr. Removing PropertyInitializationExpr entries for methods called from the constructor does not affect properties with defaults — they are still correctly flagged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 72cd601 commit db70c6c

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

tests/PHPStan/Rules/Variables/IssetRuleTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,24 @@ public function testBug13473(): void
567567
{
568568
$this->treatPhpDocTypesAsCertain = true;
569569

570-
$this->analyse([__DIR__ . '/data/bug-13473.php'], []);
570+
$this->analyse([__DIR__ . '/data/bug-13473.php'], [
571+
[
572+
'Property Bug13473\FooWithDefault::$bar (int) in isset() is not nullable.',
573+
28,
574+
],
575+
]);
571576
}
572577

573578
public function testBug13473Method(): void
574579
{
575580
$this->treatPhpDocTypesAsCertain = true;
576581

577-
$this->analyse([__DIR__ . '/data/bug-13473-method.php'], []);
582+
$this->analyse([__DIR__ . '/data/bug-13473-method.php'], [
583+
[
584+
'Property Bug13473Method\FooWithDefault::$bar (int) in isset() is not nullable.',
585+
34,
586+
],
587+
]);
578588
}
579589

580590
}

tests/PHPStan/Rules/Variables/data/bug-13473-method.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ public function setBar(int $bar): void
2020
$this->bar = $bar;
2121
}
2222
}
23+
24+
class FooWithDefault {
25+
private int $bar = 1;
26+
27+
public function __construct(int $bar)
28+
{
29+
$this->setBar($bar);
30+
}
31+
32+
public function setBar(int $bar): void
33+
{
34+
if (isset($this->bar)) {
35+
throw new \Exception('bar is set');
36+
}
37+
$this->bar = $bar;
38+
}
39+
}

tests/PHPStan/Rules/Variables/data/bug-13473.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ public function __construct(int $bar)
2020
$this->bar = $bar;
2121
}
2222
}
23+
24+
class FooWithDefault {
25+
private(set) int $bar = 1 {
26+
get => $this->bar;
27+
set(int $bar) {
28+
if (isset($this->bar)) {
29+
throw new \Exception('bar is set');
30+
}
31+
$this->bar = $bar;
32+
}
33+
}
34+
35+
public function __construct(int $bar)
36+
{
37+
$this->bar = $bar;
38+
}
39+
}

0 commit comments

Comments
 (0)