Adoption levels of recent PHP features
While browsing the PHP devsquad, I ran into this article that listed the top 10 powerful features of PHP. Beside the list, it made me wonder what are the adoption levels of recent PHP features, based on this list.
Once in a while, I like to check such top 10, to see how main stream PHP features are becoming. After all, there is a step between what is announced at the new version release, and how features are adopted (I’m looking at you, spaceship operator. And working on Exakat tends to keep me looking at exotic parts of PHP.
A Top 10 PHP Features
Here is the list from the article. Can you find your own favorite features?
- Generators
- Traits
- Anonymous Classes
- Null Coalesce Operator
- Ellipsis (Variadic, …) Operator
- DateTimeImmutable Class
- Iterator
- Arrow Functions
- Named Arguments
- Match Expression
PHP Features Adoption in Open Source Code
Now, here is a survey that check how these features are used, in a corpus of over 3100 PHP open source projects.
- Generators 11,00 %
- Traits 33,00 %
- Anonymous Class 17,00 %
- Coalesce 47,00 %
- Ellipsis (…) 31,00 %
- DateImmutable 16,00 %
- Iterator 34,00 %
- Arrow Functions 23,00 %
- Named Arguments 21,00 %
- Match 17,00 %
Over one third of adoption in the code for Iterators, Ellipsis Coalesce and traits: to compare with, arrays
are used in 66% of all projects, so that’s a good level, compared to one of the PHP star features.
Generators, Match, DateTimeImmutable and Anonymous Classes may need a bit more drum rolling, or more wide spread use cases. There are quite a number of tutorials to create them, but are there enough use cases blogs to help push their usage? When you have some ready, ping me on dseguy.bsky.social, or on the Dev Squad !
Personal adoption of PHP Features
I reviewed the list, and, honestly, I can say I have adopted half of them. Generators, Coalesce, ellipsis, named arguments and match are common.
I don’t work with dates, so that leave DateTimeImmutable out. I have found little use of Traits so far. I’m happy with Closures, in place of Arrow functions, and Generator, in place of Iterators. And I name every CITE in the code.
Limitations of the survey
The figures above are extracted from analyzing 3100+ PHP open source projects. Such projects may be small or big, and bigger projects tends to use more features. Some may be more recent than others, and some keep backward compatibility very high in the priorities. They include the top 1000 packages, the most common frameworks and applications, and some lesser known.
PHP is modernizing, one code after the other
After a few years, it is interesting to check the adoption level of released features. They become actually adopted once they found their usage in everyone’s code, as much as possible.
While a top 10 PHP features is probably a bit arbitrary, it is good to see the community choice getting PHP more modern.