9 ms·
No, you just need strict comparison (like you need it in JS and any other language with weak typing): php > var_dump('9223372036854775807' == '922337203685
by vladev 15y ago
No, you just need strict comparison (like you need it in JS and any other language with weak typing):
php > var_dump('9223372036854775807' == '9223372036854775808');
bool(true)
php > var_dump('9223372036854775807' === '9223372036854775808');
bool(false)
- eblume 15y agoI beg your pardon, but you do not 'need it in JS', if 'it' is referring to using === instead of == to compare strings. Here is what node.js says: > "9223372036854775807" == "9223372036854775808" false
- mikeryan 15y agoAh but more fun with Javascript >>> "9223372036854775807" == "9223372036854775808" false >>> 9223372036854775807 == "9223372036854775808" true >>> 9223372036854775807 == 9223372036854775808 true I believe the grandparent post is more referring to "general" use cases then this one. Personally I now default to strict comparison operators both in JS and PHP unless I explicitly want a loose comparison and end up missing most of these strange vagaries these days.
- tlrobinson 15y agoNot in this case, but it's commonly accepted that == is "broken" in JavaScript, and === should be the equality operator of choice most of the time. The one case where I sometimes use == is if I want to check for "null" or "undefined". Even then it scares me.