Skip to content

Commit 7a6c50a

Browse files
phpstan-botclaude
andcommitted
Add test for property with default value in set hook isset check
When a property has a default value (e.g. $bar = 1), it is always initialized, so isset() in a set hook should still report an error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5cbf11b commit 7a6c50a

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

tests/PHPStan/Rules/Variables/IssetRuleTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,12 @@ public function testBug13473(): void
531531
{
532532
$this->treatPhpDocTypesAsCertain = true;
533533

534-
$this->analyse([__DIR__ . '/data/bug-13473.php'], []);
534+
$this->analyse([__DIR__ . '/data/bug-13473.php'], [
535+
[
536+
'Property Bug13473\Bar::$bar (int) in isset() is not nullable.',
537+
30,
538+
],
539+
]);
535540
}
536541

537542
public function testBug14393(): void

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ public function __construct(int $bar)
2222
}
2323

2424
$foo = new Foo(10);
25+
26+
class Bar {
27+
private(set) int $bar = 1 {
28+
get => $this->bar;
29+
set(int $bar) {
30+
if (isset($this->bar)) {
31+
throw new \Exception('bar is set');
32+
}
33+
$this->bar = $bar;
34+
}
35+
}
36+
37+
public function __construct(int $bar)
38+
{
39+
$this->bar = $bar;
40+
}
41+
}

0 commit comments

Comments
 (0)