13
The following operation returns true:
var_dump("1" == "1e0"); //1 == 1 -> true
But if I add an "e" at the end of the second string, it already returns false:
var_dump("1" == "1e0e"); //1 == 1 -> false???
If you do the following operation, returns 2:
echo (int)"1" + (int)"1e0e"; // 2
My question is, why the second operation returns false if in the third operation, I am converting the values to integer and returns 1 + 1, ie in the second operation the comparison should be 1 == 1, would not have to return true?
Another question is, if I am comparing 2 strings, why does the first operation return true if they are two different strings?
This is one of the many drawbacks of PHP. This "achism", this "intrusion" is a major cause of difficult to debug bugs.
– Bruno Augusto
So, why in the var_dump function the string "1e0" is converted to numeric but the "1e0e" is not? It should not convert to 1 as it does at first without the need of (int) before the string?
– Filipe Moraes
@Felipe because as already said in the reply
1e0e
is not a notation valid scientific.– Mansueli
@Brunoaugusto I agree, if I’m comparing Apples to Oranges, it’s not because both are fruits that I want them to return
true
.– Kazzkiq
Blessed be the polymorphism provided by interfaces \the/
– Bruno Augusto