3 ms·
"If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number" And a string that doesn't look
by tyingq 6y ago
"If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number"
And a string that doesn't look like a number at all is converted to 0.
No, I'm not condoning this madness.
- coldtea 6y agoWell, in C you can cast any random set of bytes to an int, so there's that...
- overgard 6y agoSure but in C you usually do that explicitly, on purpose. Here it's almost certainly not what you wanted or expected.. Also, C is 20-30 years older and I don't think I've ever read anyone really compliment its type system in any way other than saying it's simple.
- andreygrehov 6y agoIf one doesn't know the language, they can write shitty code, regardless whether it's C or PHP. Any decent PHP programmer knows about the `===` operator that doesn't do any type juggling.
- tyingq 6y agoThis problem isnt really fixed with === per se. Converting strings to numbers is a common need, and the weird type conversation here is broken (and being fixed) for more than just implicit conversions in comparisons. The PHP team is calling it "saner numeric strings"...seems to indicate they agree.