Features that make PHP go forwardFeatures that make PHP go forward

Open source projects often support older PHP versions, and sometimes, really much older. At some point, they take the decision to move on. With the drop of older versions, (relatively) new features can be used to modernize the sources. These features are the ones that make PHP go forward: they are wanted and awaited.

To detect which PHP features are important enough to trigger the abandonning of arcane PHP versions, we went a wide spanning audit and linted 51 modern PHP projects with PHP 8.0 and 7.4. Then, we checked what syntax error does the code yield with old PHP versions. By using these features, the backward incompatibility with now gone.

General compatibility with PHP 7.4 and 8.0

Out of the 51 projects, 18 projects generate no linting error with PHP 7.4; 20 projects generate no linting error with PHP 8.0. This gives 35% of PHP projects are still ensuring backward compabitibility with PHP 7.4; and a little less than 40% are ensuring PHP 8.0 backward compatibility.

The other projects are all displaying some incompatibility with these versions. It ranges from 1 file to 695 files, or up to 14% of the code base, incompatible with PHP 8.0.

Most frequently adopted features for PHP 8.0

Here are the most frequent features that are making the code backward incompatible. The percentage is the number of projects that are displaying a related error, divided by the number of projects that are backward incompatible. For example, an enumeration enum e {}yield syntax error, unexpected identifier "e" in PHP 8.0, and not in PHP 8.1.

The enumerations (PHP 8.1) are the feature that most often breaks backward incompability in modern code: it happens in 45% of the projets.

Then, readonly properties (PHP 8.1) while readonly classes are not yet visible. Intersectional types (A&B, PHP 8.1) and first class callable (strlen(…), PHP 8.1) are all close, with about 20% of compatibility breaks.

Last, but not least, are constant visibility and final classes. Final classes are not appearing.

Most frequently adopted features for PHP 7.4

When projects reach PHP 8.0, they start using the following features:

Promoted properties is a clear winner for adoption. It is a reason to drop backward compatibility in 2 cases out of 3.

Other omitted errors

There are a lot more incompatibilities between PHP middle versions (PHP 8.1, PHP 8.2, PHP 8.3…) than simply lint. Notably, the linting process stops at the first encountered error, and there may be a lot more errors later. Yet, this audit only counts the first one.

Also, some incompatibilities are only visible at execution time: they are left out of this analysis.

Choosing the features that make PHP go forward

It is interesting to discover which are the PHP features that are awaited, in projects that prevents themselves from using them to preserve PHP backward incompatibilities.

It is a reverse scenario, compared to the delivery of a new PHP version. When the project decides to move one, these new features are widely available, and usually well understood by coders. This prevents using features because they are new or fashionable. Only the real ones are adopted.