3 ms·
PHP's weird Comparisons
We all know that PHP's comparisons my feel kind of weird but at least i thought it would follow some reasonable rules.
Recently i came across some comparisons, that may follow rules, but make me feel really uncomfortable using the == operator, when comparing strings:
// true
var_dump("+09"=="009");
var_dump(" 09"=="009");
var_dump(" -09"=="-009");
var_dump("\t-09"=="-009");
var_dump("\t\n-09"=="-009");
var_dump("+0"=="-0");
var_dump("09"=="009");
var_dump("9"=="009");
// false
var_dump("+ 09"=="009");
var_dump("- 09"=="-009");
Keep in mind: I am comparing strings, NOT numbers.