I'm reaching out because I'm facing a case where PHPStan and this set of rules contradict each other. It's one of the default rules, specifically the rule for instanceof.
I have a situation where a class is set only if a condition is met. Previously, I used isset() for this with no issues, but now I'm being recommended to use instanceof, which I completely agree with. However, when I use instanceof without isset, PHPStan tells me that the variable might be undefined. So, I added isset before instanceof, but then type-perfect says to use instanceof instead of isset.
Hello,
I'm reaching out because I'm facing a case where PHPStan and this set of rules contradict each other. It's one of the default rules, specifically the rule for instanceof.
I have a situation where a class is set only if a condition is met. Previously, I used isset() for this with no issues, but now I'm being recommended to use instanceof, which I completely agree with. However, when I use instanceof without isset, PHPStan tells me that the variable might be undefined. So, I added isset before instanceof, but then type-perfect says to use instanceof instead of isset.
Here is an example where PHPStan says the variable might not be defined: https://phpstan.org/r/9486e811-bc55-467f-a487-03a858286fdf
edit: After some testing it seems that phpstan is right and we need to verify with isset() that the variable exist