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

I'd love to see a modern PHP without all the warts but with the ease of use.


I think you are in for a treat, then, because PHP 8 is way different from PHP 5.


Unless they have abandoned backwards compatibility then I don't think that is what I meant.


Major differences that I can think of between the two are (with regarding to warts and ease of use):

PHP 8 uses exceptions with a unified Error hierarchy, there are type errors, division by zero, certain parse errors and so on.

PHP 8 has strong support for static typing now, thank goodness.

PHP 8 introduces union types (int|float|null).

PHP 8.1 introduces intersection types (A&B).

PHP 8.1 added the "never" return type.

PHP 8 has less repetitive boilerplate.

PHP 8 has consistent function signatures now.

PHP 8 has consistent object/array syntax now (to be honest, some asymmetries remain).

PHP 8 has named arguments for clarity and flexibility.

PHP 8 has the nullsafe operator which simplifies deeply nested null checks.

PHP 8 has arrow functions which makes closures concise and easier to use.

PHP 8 has attributes, e.g. "#[Route("/users")]".

PHP 8 has "match" expressions which is a more predictable, type-safe, and expression-oriented alternative to "switch".

PHP 8 has many more tools for testing and debugging (incl. static analyzers).

PHP 8 has many new functions (incl. utility functions).

PHP 8.1 introduces native enums.

PHP 8.1 has "readonly" properties for enforcing immutability.

PHP 8.1 has cleaner syntax for referencing callables.

PHP 8.1 has "fibers" which enables cooperative multitasking and is a foundational building block for upcoming async/await features.

Global namespace pollution has been pretty much resolved (Composer autoloading[1]).

There are other ecosystem-level improvements such as PSR standards[1], better async story, etc.

This list is non-exhaustive. These are just the improvements that come to mind off the top of my head so I probably missed a lot of other major improvements. PHP 8+ is definitely much easier to use and they greatly reduced PHP's warts. There may be some inconsistencies left here and there, but they are not a deal-breaker IMO, if you even run into them.

[1] https://www.phptutorial.net/php-oop/php-composer-autoload/ (I do not use "dump-autoload"), https://github.com/php-fig/fig-standards/blob/master/accepte..., https://www.php-fig.org/psr/psr-4/ (https://www.php-fig.org/psr/)

---

I strongly recommend taking a fresh look at PHP 8+. It is very different from the PHP you have once known. It is "modern" now. There are lots of deprecations and removal of old warts. I did not like PHP as much ages ago, but it was a pleasure to use PHP 8+.

If you are looking to (re)learn PHP, the book “PHP & MySQL: Novice to Ninja” is a good starting point[1]. There are many other, high-quality books and resources as well.

[1] Available on libgen. The source code examples from the book are available on GitHub: https://github.com/spbooks/phpmysql7.

---

If you have any specific warts or whatnot, or if you want more resources, please do feel free to let me know.

---

I wrote this comment on my phone, so it is not as detailed and it is not structured as well, but I hope that it will still provide some insight into the differences between legacy PHP and modern PHP.

Happy to answer any questions!


That's great but unless you have given up backwards compatibility then you are still going to have all the warts.


Additionally, PHP 8.5 will have the pipe operator.

https://thephp.foundation/blog/2025/07/11/php-85-adds-pipe-o...


Wow very in depth comment. Maybe I'll spin up a dev container and play around with php


I missed an important difference (because I did not consider it to be relevant to "warts"[1] and "ease of use"), which is that modern PHP has Just-in-Time (JIT) compilation now, not an interpreted runtime, which offers significant performance improvements!

[1] On second thought, poor performance could be considered a wart.


That’s called Python or Ruby.

I’ve been building web apps since the ’90s, and I never understood the appeal of PHP. It was always a terrible language, and there were usually better alternatives available.




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

Search: