Skip to content

Fix InvalidComparisonOperationRule for UnionType #4168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

I'm not sure about the purpose of the InvalidComparisonOperationRule which seams to forbid comparison between number and object or number and arrays. Technically something like $int == $array is supported by php (and 0 == [] for instance).
Maybe the message

Comparison operation "!=" between array and 0 results in an error.

should be improved, but that's another topic.

Looking at the implementation, both isPossiblyNullableObjectType and isPossiblyNullableArrayType shouldn't use the RuleLevelHelper, because it will removed non-array/non-object on lower level and this is the reason why an error happen on level 6 (and then disappear in level 7).

Finally, I notice that currently a comparison between int and object|array is not reported.
This is easy to fix, but since I dunno the whole purpose of this rule, I prefer to ask you first @ondrejmirtes if I should fix it too.

Closes phpstan/phpstan#3364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Level 6 - Comparison operation ... results in an error ; Level 7 - No errors
1 participant