Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  0 == 'foobar' // false
> When comparing to a numeric string, PHP 8 uses a number comparison. Otherwise, it converts the number to a string and uses a string comparison.

Why do the conversion at all? Why couldn't this just be an error? I realise there is also `===` the strict comparison that typechecks arguments, but why not make that the default?



> Why couldn't this just be an error?

you mean crash your program? So your user finds a way to send you an int instead of a string, or vice versa, and now they can crash your webserver.


technically they'd just crash that one php process, not the whole web server. :)

I think the bigger 'why not' is ... 25 years of backwards compatibility.


Oh right ^^ that’s actually one really cool thing about php web apps, no easy denial of service attacks


(again) technically it could trigger a warning (actually, I thought perhaps it did that years ago??)

It's still pretty easy to DOS the server that is passing requests to PHP.

The 'shared nothing' approach has other benefits though - primarily not having to concern yourself with concurrency issues or shared memory resources. You can dive in to deep PHP and do that, but it's not something beginners need to be thinking about.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: