Hacker News new | ask | show | jobs
by apexauk 6499 days ago
agree about failing loudly when bad stuff happens - but exceptions are best reserved for truly exceptional circumstances. in webdev everything arrives from the browser as a string so implicit casting is more of the norm. if your user enters something dumb into the quantity field of your shopping cart it doesn't really warrant abandoning the rest of their input and leaping back up the call stack to a "misson failed"-level error handler.

functions like is_numeric('string') exist for the rarer situations where things like this actually matter, but php's default way is simply reflective of it's nature as a loosely-typed language.