Add operand types to DisallowedLooseComparisonRule error message#294
Merged
ondrejmirtes merged 1 commit intophpstan:2.0.xfrom Feb 11, 2026
Merged
Add operand types to DisallowedLooseComparisonRule error message#294ondrejmirtes merged 1 commit intophpstan:2.0.xfrom
ondrejmirtes merged 1 commit intophpstan:2.0.xfrom
Conversation
Member
|
Hi, we can't do this change in a minor/patch version because it'd break people's baselines. This can be done by changing the error message only when the bleedingEdge toggle is on. You can inject the parameter into the rule with |
8dc2d6c to
eb67092
Compare
Contributor
Author
|
Thanks for the suggestion, I added an I also added a tip about the use case to README. |
ondrejmirtes
requested changes
Feb 11, 2026
README.md
Outdated
| | `switchConditionsMatchingType` | Types in `switch` condition and `case` value must match. PHP compares them loosely by default and that can lead to unexpected results. | | ||
| | `dynamicCallOnStaticMethod` | Check that statically declared methods are called statically. | | ||
| | `disallowedEmpty` | Disallow `empty()` - it's a very loose comparison (see [manual](https://php.net/empty)), it's recommended to use more strict one. | | ||
| | `disallowedLooseComparison` | Disallow loose comparison via `==` and `!=`. You can use `includeOperandTypesInErrorMessage` to ignore some cases, for example `DateTime` object comparison. | |
Member
There was a problem hiding this comment.
Please remove the mention of includeOperandTypesInErrorMessage. It's not user-accessible and it's not meant to be.
Contributor
Author
There was a problem hiding this comment.
Ah, right. Removed.
ondrejmirtes
approved these changes
Feb 11, 2026
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes it possible to ignore
disallowedLooseComparisonissues for certain builtin PHP classes with overloaded comparison operators:BcMath\NumberDateTime(Resolves disallowedLooseComparison - allow only DateTime/DateTimeImmutable #232)Currently the error message doesn't include types:
This adds operands types to make the errors ignorable: