The upgrade sandwich

With PHP 8.1 released last month, it is time to learn PHP 8.1 new features, and consider upgrading PHP code to PHP 8.0 new features.

Wait a second… upgrade to PHP 8.0 ? Surely you mean, 8.1.

Migrating to a new PHP version

Migrating to a new version is actually a simple process, in four steps :

  • Learn about the new PHP features
  • Upgrade your code from PHP 8.0 to PHP 8.1
  • Upgrading the dependencies
  • Start using PHP 8.1 new features

Learning about PHP new features

The first step is the most natural one : a new version, PHP or else, is only as interesting as its new features. The list is available in the PHP source code, in the NEWS file, but also in a more concise manner in the UPGRADING file.

There are also many authors that are detailing them, like What’s new in PHP 8.1, What’s New in PHP 8.1: Features, Changes, Improvements, and More , Top 10 PHP 8.1 Features You Should Start Using Now.

Bug fixes are also a major improvements, though they are usually provided with minor versions, even in the current middle version. As they tend to bother a part of the PHP user base, they are published faster than the yearly release cycle.

Upgrading your own code

Interestingly, learning about the new features is probably too early. The actual first step toward a new version is making the current code compatible with it. There are always pre-requisites before migrating to the new version, usually called ‘backward incompatibilities’.

This means that after learning about the new features of the upcoming version, you have to learn about the incompatibilities and how to fix them. Luckily, there are also online documentation for this, such as the Migrating from PHP 8.0.x to PHP 8.1.x or the CompatibilityPHP81 Exakat ruleset.

Upgrading the dependencies

The dependencies will mainly be other composer packages. Indeed, they will have to follow the same process as your code, and proceed with their own release cycle. And, if they also have dependencies, they might also be on hold, waiting for other packages to upgrade, so they can in turn.

At that point, it is interesting to consider speeding up the process by contributing directly to those components. After all, help a package is also a way to help yourself, so this is mostly some simple egoism put to work.

Adopting the new previous features

Another option to take advantage of this time gap is to consider that you have already done all that work for the previous version. Meaning that preparing to upgrade to PHP 8.1 means that your code is most probably at PHP 8.0 level. That way, it is at the same time waiting for the new features, and ready to adopt the PHP 8.0 features.

In fact, adopting new features is not a compulsory step : there is a freedom in adopting them, which is not available with the incompatibilities. The incompatibilites are imperative : you won’t upgrade until they are satisfied. On the other hand, new features can (and will) wait for a decision of adoption. Sometimes, they wait for a long time, and they may even get forgotten.

Upgrading to PHP 8.0

So, let’s make a simple exercice : do you remember any PHP 8.0 new features ? What’s new in PHP 8, 8 Top New Features in PHP 8. May be it is time to review them and actually use them. They are still available, and they might be easier to adopt than the PHP 8.1 ones.

Exakat includes a complete Ruleset Suggestions, dedicated to adopting new features. It searches for possible patterns of modernisation and allow you to decide if it is pragmatic to adopt them. They may be PHP 8.0, 8.1 or even older. You’ll be suprised.