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
Type of child object is not infered if get_class is used outside of switch argument #523
For now I've just moved the get_class inside the switch statement since it wasn't an issue, but now that I'm thinking about it, your approach is better performance-wise, since it's not comparting two strings but just checking the type of an instance, which is more correct and faster; thanks!
Activity
ondrejmirtes commentedon Sep 28, 2017
Yep, PHPStan is not that smart yet 😊 Try to make the code more understandable for the static analyzer.
Alternative (also understood) approach is this:
Jean85 commentedon Sep 28, 2017
For now I've just moved the
get_classinside the switch statement since it wasn't an issue, but now that I'm thinking about it, your approach is better performance-wise, since it's not comparting two strings but just checking the type of an instance, which is more correct and faster; thanks!ondrejmirtes commentedon Dec 2, 2020
Closing this in favour of: #1239
ondrejmirtes commentedon Dec 2, 2020
Oh, this is actually for dependent types.
gbirke commentedon Apr 8, 2022
I have made another example where this fails for
get_classinside amatchstatement:https://phpstan.org/r/d6117a8f-0255-479d-b681-e45396ce79df
phpstan-bot commentedon Jun 19, 2023
@gbirke After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.1
No errors
PHP 7.1 – 7.4 (3 errors)
Syntax error, unexpected ',' on line 53Syntax error, unexpected T_DOUBLE_ARROW on line 53Syntax error, unexpected '}' on line 55