no inspection for invalid enum to string comparison Follow
I would expect to get a warning if I compare a backed enum to a string without using ->value
The code below does not complain when using ==. Only with ===.
However, what should it cast to when using == ? In my opinion it this comparison never makes sense and it should therefore highlight it even when just using ==
enum UserType: string {
CASE ADMIN = 'admin';
}
function doSomething (UserType $userType) {
if('someInvalidType' == $userType) {
echo 'test';
}
}
Please sign in to leave a comment.
For reference purposes: the same on on StackOverflow -- https://stackoverflow.com/questions/75316513/phpstorm-missing-warning-about-invalid-enum-comparison
Thanks for bringing our attention to this scenario.
I have submitted a corresponding YouTrack report:
https://youtrack.jetbrains.com/issue/WI-71398/New-inspection-Scalar-value-compared-to-an-enum-object-instead-of-the-enums-actual-value
Please feel free to vote & subscribe.