Commit 72cd601
Fix isset() false positive for methods called from constructor
When a method that assigns a property is called from the constructor,
PHPStan merges the property initialization state back into the
constructor scope. This caused a false positive when the same method
used isset() to check if the property was already initialized, because
the preserved constructor scope incorrectly marked the property as
initialized when entering the method.
The fix removes PropertyInitializationExpr entries for properties that
a method itself initializes, when the method was called from the
constructor. This generalizes the property hook fix to also work for
regular methods.
Also extracts exitPropertyInitialization() on MutatingScope to share
the logic between property hooks and regular methods.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent c6b5dd5 commit 72cd601
File tree
4 files changed
+53
-3
lines changed- src/Analyser
- tests/PHPStan/Rules/Variables
- data
4 files changed
+53
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1608 | 1608 | | |
1609 | 1609 | | |
1610 | 1610 | | |
1611 | | - | |
1612 | | - | |
1613 | | - | |
| 1611 | + | |
1614 | 1612 | | |
1615 | 1613 | | |
1616 | 1614 | | |
| |||
2840 | 2838 | | |
2841 | 2839 | | |
2842 | 2840 | | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
2843 | 2850 | | |
2844 | 2851 | | |
2845 | 2852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
712 | 712 | | |
713 | 713 | | |
714 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
715 | 729 | | |
716 | 730 | | |
717 | 731 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
570 | 570 | | |
571 | 571 | | |
572 | 572 | | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
573 | 580 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments