no inspection for invalid enum to string comparison

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';
    }
}
0
2 comments

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.

0

Please sign in to leave a comment.