4 ms·
In this perspective, writing `strcmp` everywhere is not boilerplate, but a requirement. (Such that strcmp('9223372036854775807', '9223372036854775808');
by pestaa 15y ago
In this perspective, writing `strcmp` everywhere is not boilerplate, but a requirement.
(Such that
strcmp('9223372036854775807', '9223372036854775808');
returns -1, meaning the strings are not equal.)
- vladev 15y agoNo, 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.
- deleted 15y ago[deleted]