You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive "Readonly property is already assigned" in if-else #6402
After updating PHPStan from 1.3.1 to 1.4.1 assigning to a readonly property in the different branches of the same condition (if-else) is started to false trigger the error "Readonly property is already assigned".
Yes, ternary operator works okay, but of course it is very simplified example, in real world it is much more bigger if-else with several assignments in both branches, so it cannot be replaced with a single ternary operator.
Reacted by Jan Nedbal, Dragos Protung, Steffen Roßkamp, Martin Legát, Marvin Heilemann, gndk and Kamil Tekiela
Activity
ondrejmirtes commentedon Jan 18, 2022
Try to do this instead: https://phpstan.org/r/0c1597e0-3a95-47b1-b3db-3c715787a062
javer commentedon Jan 18, 2022
Yes, ternary operator works okay, but of course it is very simplified example, in real world it is much more bigger if-else with several assignments in both branches, so it cannot be replaced with a single ternary operator.
apfelbox commentedon Mar 10, 2022
Just ran into the same issue. I assign multiple values in the
ifbranch, so proper support would be great.tarlepp commentedon May 31, 2022
I have the same issue, it would be really great if there is proper support for
if/elseblocks - using ternary operator is not always possible.Decouple determination of job status logic into method
Decouple determination of job status logic into method
peternormann commentedon Nov 9, 2022
I ran into the same issue.
As a temporary work-around, I did this:
https://phpstan.org/r/5f37b20f-fe0b-4ec2-add0-cad3ec933032
gndk commentedon Dec 3, 2022
I just ran into this, too. But my "work-around" is actually to add those errors to the baseline, since the fix is already in progress 🙂
lukasojd commentedon Apr 27, 2023
+1
akmandev commentedon Jun 20, 2023
@ondrejmirtes I would like to fix this if you could give me some directions as I don't really know the phpstan codebase
ondrejmirtes commentedon Jun 20, 2023
@ozanakman I want to fix this using control flow graph which is gonna be a huge effort: #8192
But I just realized there might be an easier way which I'm gonna try sooner.
ondrejmirtes commentedon Jul 2, 2023
Fixed 🎉 phpstan/phpstan-src@ce3c164
apfelbox commentedon Jul 2, 2023
Hi @ondrejmirtes,
thank you so much for this fix. Does the fix also cover try-catch?
ondrejmirtes commentedon Jul 2, 2023
@apfelbox Please try it out on phpstan.org/try, and in case of unexpected behaviour open a new bug report :)
apfelbox commentedon Jul 3, 2023
Looks fixed https://phpstan.org/r/a8a1e861-1d14-4539-9f57-2269a0e8df5a
Thanks @ondrejmirtes 🙌
github-actions commentedon Aug 4, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.