You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to arithmetic operators (+/-/*///**/%), loose comparison operators should only be used for numeric values. This is true for ==, !=, <, >, <=, >= and <=>.
Using any of these operators for non-numeric values may lead to unexpected results.
The option to disallow == and != completely doesn't cover the full problem as other comparison operators are still allowed and might give unexpected result. It also disallows cases where you do want to use == because you're comparing numbers.
Given #38, the ==, !=, >= and <= should also not be used if both parts are floats. This is already covered by that PR but could be covered by this test instead.
Similar to arithmetic operators (
+
/-
/*
//
/**
/%
), loose comparison operators should only be used for numeric values. This is true for==
,!=
,<
,>
,<=
,>=
and<=>
.Using any of these operators for non-numeric values may lead to unexpected results.
The option to disallow
==
and!=
completely doesn't cover the full problem as other comparison operators are still allowed and might give unexpected result. It also disallows cases where you do want to use==
because you're comparing numbers.Good
Bad
Universal rules of logic state that if
a > b
andb > c
thana > c
The spaceship operator should also not be used for strings.
The logic behind wether or not a string is converted to a number is just to complex. It's party explained in the manual, but that's not conclusive.
For strings you SHOULD always use
===
orstrcmp
.While
==
could be useful to compare objects, the strange behaviour on strings makes this too dangerous.The text was updated successfully, but these errors were encountered: