PHP in 2021
Once a year, I look back at the recent developments in the PHP world, and also look forward to what's to come. And just like in 2020 and 2019, we're at it again!
Like I said time and time again: PHP isn't the same language it was ten years ago, and we're very thankful for that. It's a fast and reliable language, used to build large applications at scale. So let's discuss some of the most notable changes of PHP in the last year, to the language and the community.
# PHP 8 and beyond
The new major version, PHP 8, arrived late last year. I've written an extensive amount on the topic, and I won't copy/paste all of that here. As always, performance is only improving, as shown by the benchmarks done by Kinsta.
There's also the JIT that does seem to improve performance of some projects here and there, as well as preloading that has an overall positive impact if you're not using shared hosting.
I think that features like attributes (a.k.a. "annotations"), named arguments and promoted properties also deserve a mention, as they have definitely contributed towards PHP 8 being such a great release.
Meanwhile, the core team is already working on the next version, PHP 8.1, which will be released somewhere by the end of 2021. For now, the most significant features are enums and fibers, I'll mention both of them again later in this post.
Year after year, the core team succeeds in bringing a new stable release to the community, packed with a bunch of features and quality-of-life improvements. The upgrade path also isn't all that difficult anymore. I upgraded some of my own projects from PHP 7.4 to PHP 8, and it took only an hour or so per project. There really isn't any good reason to stay behind!
PHP introduces quite a lot of deprecation notices with each minor update. How to deal with them?
# PHP's type system
There's actually some very exciting news when it comes to types: enums will be added in PHP 8.1. On top of that we've also seen some of the maintainers of static analysis tools contributing to PHP's source code by landing their first RFC. This one adds the
never type, a useful addition for static analysis.
Speaking of static analysis tools, PhpStorm has added built-in support for Psalm and PhpStan, which is a great step towards broader adaptation; our favourite IDE now also supports generics as docblocks, which makes them a lot more useful.
Still no support for first-class generics, unfortunately. There are some major road blockers, especially since we're still dealing with a dynamically typed language. Nikita has outlined the problems here. Personally, my approach would be the easy way out: only support runtime-erased generics and rely on static analysis. This requires more than a technical solution though, it also requires a mind shift in the PHP community as a whole. Maybe one day it becomes a viable option, but not as of yet.
# Async PHP
There was some big news recently: PHP is getting coroutines — aka. green threads — in PHP 8.1! Although, fibers — that's what they are called — might not be as big a game-changer as you might think.
Even though fibers themselves might only be a small cog in what is the large async machine, the RFC has spiked interest in the async community again, which we can only be happy about. Async frameworks like Amphp and ReactPHP are growing in popularity, and recently Laravel announced built-in support for Swoole.
# The community
I can't go on without mentioning Composer, the de-facto standard package manager. It has had a new major release in October, 2020: Composer 2.0. This version comes with several UX improvements, but most importantly sees extreme performance improvements, sometimes even tripling its speed on clean installs.
Speaking of composer, I like to measure the current state of PHP's ecosystem by looking at the available packages over time. Last year I spoke about ±25 million downloads a day, today that number has more than doubled and we're looking at ±60 million daily downloads.
Finally, take a look at this graph, listing the amount of packages and versions over time. It can also be found on their website. You can clearly see a healthy ecosystem growing, and there's no end in sight.
# The language
Let's end with a reminder of everything that's been added to PHP these recent years. If you haven't kept up with its development, you really want to check this list out. I think it shows the growth of the community and core development team within recent years, and I'm confident there's more to come.
- Named Arguments
- Constructor Property Promotion
- Short closures
- Null coalescing operator
- Typed properties
- Spread operator
- The JIT
- Return type declarations
- Lots more
All of that to say: PHP is alive and doing very well. Every year I feel happier with the direction the language is going, and am looking forward to using it for many years to come!
If you're excited as well, you probably want to subscribe to my newsletter to stay up-to-date about PHP's development, as well as follow me on Twitter. Let me know your thoughts via Twitter or email, and share this post with your audience if you found it useful, thanks!