4 ms·
> The language is very unplanned, go look at an equality chart for PHP, it makes JavaScript blush as well. This has been fixed in PHP 8. https://wiki.php.net/
by chx 3y ago
> The language is very unplanned, go look at an equality chart for PHP, it makes JavaScript blush as well.
This has been fixed in PHP 8. https://wiki.php.net/rfc/string_to_number_comparison https://wiki.php.net/rfc/string_to_number_comparison
- xigoi 3y ago> make non-strict comparisons more useful and less error prone, by using a number comparison only if the string is actually numeric. Otherwise the number is converted into a string, and a string comparison is performed. That… makes it even worse.
- slim 3y agowhy?
- xigoi 3y agoBecause now the behavior of comparison depends on whether the string looks like a number.
- chx 3y agoArguably 48 == "48" should be true. If this doesn't work for you, stick to ===.
- xigoi 3y agoThank you, I'll stick to languages where you can't just compare numbers and strings without an explicit conversion. Also, should 48 == "48.0" be true? How about "048", "48.", "0x30", " 48 ", "48foo", "3*16", "XLVIII", "forty-eight"?