Hacker News new | past | comments | ask | show | jobs | submit login

"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.




Well, in C you can cast any random set of bytes to an int, so there's that...


Sure 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.


If 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.


This 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.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: