Skip to content

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

if ($this->isNumberType($scope, $node->left) && $this->isNumberType($scope, $node->right)) {
$isLeftNumberType = $this->isNumberType($scope, $node->left);
$isRightNumberType = $this->isNumberType($scope, $node->right);
if (($isLeftNumberType && $isRightNumberType) || (!$isLeftNumberType && !$isRightNumberType)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about xor instead? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never used it, i'll try.

Offtopic @ondrejmirtes I saw you merged/review multiple of my PRs. I dunno if you plan a release. I just wanted to inform you I dont have access to a computer until Wednesday. So if you want to include one of my pr (with requested changes) feel free to push on it and if any of these PR introduce a regression I wont be able to fix it before Wednesday.

It's maybe not a big issue for you, just wanted to inform you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, thank you for letting me know. I don't think there will be a major issue, PHPStan is continuously tested on several real-world projects (millions of LoC) so I know about the real issues pretty soon.

If something still comes up that a lot of people have problem with, they can wait on a one-before-last version before they upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplification was easy finally
e14567b

@ondrejmirtes ondrejmirtes merged commit b7b57c1 into phpstan:2.1.x Sep 12, 2025
450 of 456 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm
Copy link
Contributor

staabm commented Sep 12, 2025

@VincentLanglet please see issue bot results for related regression tests:
https://github.com/phpstan/phpstan-src/actions/runs/17613710896

@staabm staabm mentioned this pull request Sep 12, 2025
@VincentLanglet
Copy link
Contributor Author

@VincentLanglet please see issue bot results for related regression tests: phpstan/phpstan-src/actions/runs/17613710896

Yeah, I sometime forget...
Would been great to have the bot posting on the PR ^^'

Do you think it closes phpstan/phpstan#9386, it's unclear to me...

@ondrejmirtes
Copy link
Member

@VincentLanglet Unfortunately I don't know how to do it in a secure way.

@ondrejmirtes
Copy link
Member

Looks like it does close phpstan/phpstan#9386.

@staabm
Copy link
Contributor

staabm commented Sep 12, 2025

Yeah, I sometime forget...

me too. no worries.

@staabm
Copy link
Contributor

staabm commented Sep 12, 2025

Unfortunately I don't know how to do it in a secure way.

@ondrejmirtes I guess you fear someone could steal the bot token or similar things?

maybe the issue-bot could just emit a pull request annotation with a link to the job-summary in case changes are present.
that way we would see that results exist.

this can be done just with a "echo", and without any further api tokens

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

3 participants