Skip to content

Commit efb11ec

Browse files
committed
Property is also read for ??= and other assign ops
1 parent 19fab3f commit efb11ec

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ private function processStmtNode(
629629
if (!$node instanceof Expr) {
630630
return;
631631
}
632+
if ($node instanceof Expr\AssignOp) {
633+
$customCallback($node->var, $scope);
634+
return;
635+
}
632636
if ($node instanceof Node\Scalar\EncapsedStringPart) {
633637
return;
634638
}

tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,11 @@ public function testTrait(): void
138138
$this->analyse([__DIR__ . '/data/private-property-trait.php'], []);
139139
}
140140

141+
public function testBug3636(): void
142+
{
143+
$this->alwaysWrittenTags = [];
144+
$this->alwaysReadTags = [];
145+
$this->analyse([__DIR__ . '/data/bug-3636.php'], []);
146+
}
147+
141148
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bug3636;
4+
5+
class Foo
6+
{
7+
8+
/** @var \DateTimeImmutable */
9+
private $date;
10+
11+
public function getDate(): \DateTimeImmutable
12+
{
13+
return $this->date ??= new \DateTimeImmutable();
14+
}
15+
16+
}

0 commit comments

Comments
 (0)