Hacker News new | ask | show | jobs
by cletus 684 days ago
It's disappointing that PHP still gets hate in 2024. PHP of 2024 isn't the PHP of 2004. As someone with a bunch of experience in Java, C, C++, Python, PHP, Hack, Javascript and a handful of others, PHP is (IMHO) almost a perfect language for serving HTTP requests because of these characteristics:

1. Essentially an HTML document is a valid PHP program. This is an excellent starting point for beginners;

2. PHP has a stateless API that means there's basically zero start up cost, unlike, say, loading libraries like you do in Java or even Python;

3. There's no threading within the context of a request. This is what you want 99.99% of the time. Hack extended this with cooperative async/await;

4. Because of (3) everything you allocate/use within a request context just gets thrown away. There's no persistent state (eg like Java's servlet model). Again, this is almost ideal;

5. Because of all the above, PHP hosting is incredibly cheap and accessible.

The two things I'd probably add to PHP come from Hack: a modern type system with nullable support and the collections (vec, map, set).

2 comments

IMHO most of hate is just because it is fashionable to hate some languages including PHP and Perl. But there is some criticism which looks valid to me e. g. [1]

Regarding embedded into HTML PHP code - it's a easy for beginners but in a large application it leads to hard to maintain mix of app logic and presentation - AFAIK this feature is rarely used outside toy project for many years.

[1] https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ (very old and some issues may be were addressed but it's hard to fix all of this without creating an incompatible language)

Embedding PHP in HTML is often treated as a kind of dirty legacy we don’t talk about, even though is actually an amazing prototyping feature. As long as you use it like you would use Jupyter notebooks, you’re golden.
Honestly speaking, the main thing that always made me dislike PHP was lots of things related to the syntax. Call it petty, but it's the truth.

I've always felt that PHP could greatly benefit from a Kotlin-esque interop language with a more modern syntax and QoL upgrades, but I'm not sure if the juice is really worth the squeeze.