Closed InvisibleSmiley closed 2 months ago
Thanks for reporting. This is clearly incorrect, as mixed
type overrides property type, at least from PHPStan point of view.
Param type or instanceof must be added to make code valid :+1:
Well in that case I feel PHPStan is stupid, but that's not your fault.
Psalm behaves the same in principle, but at least tells you that it is unable to infer the type for the assignment so you see where it starts to fall apart. I think that happens on the default level 2. PHPStan only does that on level 9 (and I'm on level 8).
I understand that the assignment is debatable and that anything following it is merely a subsequent fault, but the call really is not a problem.
Thanks for explaining though.
Situation
A mixed value assigned to a typed property leads to an error being reported for a call on that property when
no_mixed_caller
is enabled. That is wrong because the call is perfectly safe if it is valid according to the property type. If the mixed value was not a subtype of the property type, a (PHP) error would occur right there.It doesn't matter where the mixed value is coming from; could be a method call, parameter, variable, ...
Test Case