-
Notifications
You must be signed in to change notification settings - Fork 523
Nothing is lower than null and object is never equal to null #4131
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
Conversation
5cab013
to
1ea2f34
Compare
@@ -13,11 +13,19 @@ trait UndecidedComparisonCompoundTypeTrait | |||
|
|||
public function isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic | |||
{ | |||
if ($otherType->isNull()->yes() && $this->isObject()->yes()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This add some logic in the trait but I didn't find another way except creating an ObjectComparisonCompoundTypeTrait and an ObjectComparisonTypeTrait.
Do you prefer to create two new traits ?
This pull request has been marked as ready for review. |
@@ -110,6 +110,10 @@ public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryL | |||
return $otherType->isGreaterThan($this, $phpVersion); | |||
} | |||
|
|||
if ($otherType->isObject()->yes()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title says "Nothing is lower than null" but this change sounds to me like the opposite.
The method asks "is null smaller than object?" and you return "yes".
Maybe I'm running on fumes with only half the brain but I'd like this to be explained. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I missed some explanation.
Nothing is lower then null so
null <= $anything
is always true
$anything < null
is always false
And an object cannot be equal to null so
null < $object
is always true
$object <= null
is always false
1ea2f34
to
819afd2
Compare
Thank you! |
Closes phpstan/phpstan#10719
Closes phpstan/phpstan#9141
$a < null is always false.
$a <= null is always when $a is an object.
It needs #4132 first.