Stefan R. answered • 02/06/20

Senior PHP developer with 10+ years of experience

PHP, similar to JavaScript, has evolved to a somewhat optional strictness of types.

What you describe could theoretically become a concern. Lets say $a is a float, resulting from a former operation/calculation. And $b is an integer.

Now, based on the precision problem, $b could in theory result in having a slightly different value than mathematically accurate.

As comparison operators themselves are strict, this could result in e.g. $b > $a being true while $b == $a false even though the values are the same from a mathematical perspective. This goes as far as

In this case $bool is false, even though you expect it to be true. The solution is to round your values accordingly. You will find references to epsilon as a method of fighting this, but don't forget that complex mathematical operations could go through many calculations before you can determine the "offset".

About your example:

So what are the possible outcomes here?

- both expressions are true: the overall result is false
- one expression is false, the other true: the overall result is true
- both expressions are false: the overall result is false

So since you excluded that they are equal in your example, I can't think of any scenario that wouldn't securely hit the second possibility, regardless of type of number(s)