PHP 8 - Worth the update?
The 26.11.2020 was circled in red in the calendars of many developers, because then the long-awaited version PHP 8.0 was released. What new features and improvements does the new version contain and how and when should you switch to PHP 8.0?
We have summarised this information in the blog post - and will update it continuously over the next few weeks.
The new version PHP 8.0
As the version number shows, this time it is a major release, which implies some changes that may not be downward compatible. However, this should cause fewer problems if you have always kept your PHP version up to date. However, many websites written with PHP are still using an old version that will (probably) soon no longer be supported. Keeping your website's code up to date and always using new versions of PHP has its advantages: New features not only offer greater variety, but allow for improvements in performance and security issues are fixed..
Please note that you may have to make adjustments to the code due to the improvements in PHP 8.0. You can find a list of all changes here: https://www.php.net/manual/de/appendices.php and the official documentation here: https://www.php.net/manual/en/migration80.php.
If you need a refresher on your PHP programming skills, the following PHP tutorial https://www.php.net/manual/en/tutorial.php or the course platform https://jobtensor.com/Tutorial/PHP/en/Introduction might help you.
New features and improvements
All reports in the run-up to the PHP 8.0 release agreed: The new version will be faster and more secure. Below are some selected functions and improvements that contribute to this (a complete overview of the implemented features can be found here).
JIT Compiler (“Just in time” compiler)
What is a JIT compiler or what does it do? Since PHP is an interpreted language, the code is not compiled but interpreted line by line during runtime. So far, this has already been accelerated by the PHP Opcache, which translates and caches the human-readable PHP code into a machine-readable bytecode. The JIT compiler goes one step further here, as it has a function that translates the code in places - during runtime, always "just in time" - into native assembly code. Instead of the actual PHP bytecode, this is then executed directly. Whether only frequently used functions or all functions are translated into machine code with the JIT compiler depends on the "opcache.jit" setting.
But does this feature really make applications faster? Phoronix already conducted initial tests in June and determined a performance increase of 7% when switching from PHP 7.4 to PHP 8.0 (Git, Alpha 1) and a more than 50% increase when using PHP 8.0 with JIT compiler compared to PHP 8.0 without JIT compiler:
On gitconnected there is another performance test by Pedro Escudero: https://levelup.gitconnected.com/how-fast-is-php-8-going-to-be-f7fdc111cd6. And the PHP developer Brent has also carried out some tests before the release of the current software: https://stitcher.io/blog/jit-in-real-life-web-applications. Brent comes to the conclusion that no performance increase of more than 10 % can be expected for web requests.
The extent to which the new JIT compiler can actually keep its promise regarding more performance will therefore only become clear in the next few weeks, when more tests have been made with the live version. Feel free to share your experiences with us - just write an email to firstname.lastname@example.org. We will then include them in our blog article updates.
“Named Arguments” also called "named parameters" now allow parameters to be passed to a function based on the parameter name. Previously, this was only possible via an order. Now values can be passed to a function by specifying values. Here, the order does not have to be considered and optional parameters can be skipped. Array spreading" is also supported. The innovations make the code more flexible and also make it possible to write clean code.
Static return types
“Static” is a special class name in PHP that references the class with which a method is called - even if this method is inherited. With PHP 8.0, "static" now becomes a valid return type alongside "self" and "parent".
With the help of union types, it is possible to define variables or return values and parameters that can take on several possible types. In this way, a type binding can be enforced even if the variable type is dynamic.
Attributes, also known as annotations or decorators, now provide a way to add metadata to classes without having to use document blocks. This allows the metadata to be better separated from document blocks, eliminating the need for parsing for evaluation. It is also possible to access the new attributes directly via the Reflection API.
"Weak Refs" were introduced in PHP 7.4 and allowed references to objects that did not prevent the garbage collector from destroying those objects. "Weak maps in PHP 8.0 are now a kind of upgrade of this functionality. Via "weak refs" and "weak maps", it is now possible to specify that objects can be deleted if they are only referenced by the MAP.
Especially in the case of ORMs that can manage several hundred, if not thousands, of entities within a query, "weak maps" can provide a good, more resource-efficient way to deal with these objects.
PHP 8.0 has many other innovations to offer, a small selection of which is listed below:
- DateTime and DateTimeImmutable objects can now be converted into each other.
- With the new "fdiv" function, it is possible to divide by 0 since php 8.0. The return value is "INF", "-INF" or "NAN".
- The new "Nullsafe operator (>?)" is useful when reading properties and methods, because it bypasses the rest of the code line at the first occurrence of a null value.
- The new "Constructor property promotion" allows the reduction of boilerplate code, as you can now combine construction definitions and variable assignments in one syntax in the parameter list.
- The "stringable interface" now implements an interface automatically. This step used to have to be done manually.
- The "Uniform Variable Syntax" in PHP 8.0 brings further adjustments and irons out some inconsistencies in PHP's variable syntax.
- It is now possible to pass function parameters with a trailing comma.
The full list of changes can be found here: https://wiki.php.net/rfc#php_80
What do I have to consider before updating?
Are you so interested in the new features of PHP 8.0 that you want to update immediately? There are a few steps you need to take in advance - regardless of your shop or CMS system:
- Check whether your shop or CMS system is compatible with this major version.
- Play it safe and create a backup.
- And even more security: set up a development environment, install the PHP update and carry out tests. Don't forget to test the compatibility of the plug-ins you use.
- Your tests were successful? Then you can now install the update in your live environment.
Increase the security and stability of your application by - as far as possible - always using the latest PHP version. If this is not possible, try to ensure that you are at least using a version that receives official security updates. Under the motto "Keeping Current", PHP supports this approach by continuously closing security gaps. Your advantages: the performance potential of your application increases, you will have fewer problems updating and using plug-ins and extensions, and new features can be used immediately. By the way, you can find an overview of the features of the latest version 7.4 in our blog article “PHP 7.4 -Is the update worth it?”.
Compatibility of PHP 8.0 with popular applications
The new features and improvements of PHP 8.0 have convinced you and you want to convert your application immediately? Since PHP 8.0 is only a few days "old", there is partially no information regarding the compatibility of all common applications yet. We will successively add this information in this blog article and fill the table below, so that you can use it to check whether the new version is compatible (as of 11.05.2021):
Which applications and store systems are compatible?
We will provide you with the missing information as soon as it is available.
Magento 2 and PHP 8.0
According to the system requirements, Magento 2 will not offer support for PHP 8.1 until the upcoming version 2.4.5, which itself will not be released until November 2021. An exact release date has not yet been determined. Based on the release dates known so far, a release of Magento 2.4.5 can probably be expected in the second or third quarter of 2022.
Magento 1 and PHP 8.0
Due to the end-of-life of Magento 1, it is not expected that there will be official support for PHP 8.0. Support for PHP 8.0 is already being worked on as part of the Magento "OpenMage Magento LTS" fork.
Shopware 6 and PHP 8.0
Version 18.104.22.168, released on 04 May 2021, offers support for PHP 8.0. The compatibility of themes and plugins must be checked in detail.
Shopware 5 and PHP 8.0
PHP 8.0 will be supported with the upcoming Shopware 5.7 release. So far, a release candidate has been published that can be used for testing purposes. The exact release date is not yet known.
Wordpress and PHP 8.0
Wordpress has received support for PHP 8.0 with version 5.6. This was released on December 08, 2020. The compatibility of themes and plugins must be checked in detail.
Typo3 and PHP 8.0
Status 11.05.2021 ‒ As things stand, no Typo3 version (including v11) supports the current PHP version 8.0. However, it can be assumed that older Typo3 versions will also receive support for PHP 8.0 in the medium term. This is necessary so that these Typo3 versions can be operated with an actively supported version of PHP until their respective support ends.
EOL and roadmap of current PHP versions
Of course, you don't have to switch to PHP 8.0 yet, but you should still take a look at the roadmap of the current versions to plan your next steps. Official support for PHP 7.2, for example, has ended on 30.11.2020. Some versions still receive unofficial security backports, which are also available on our clusters. However, we recommend using a current version if possible.
|<= PHP 5.5||No more security updates|
|PHP 5.6||Unofficial security backports|
|PHP 7.0||Unofficial security backports|
|PHP 7.1||Unofficial security backports|
|PHP 7.2||Unofficial security backports|
|PHP 7.3||Official security support until 06.12.2021|
|PHP 7.4||Official security support until 28.11.2022|
|PHP 8.0||Official security support until 26.11.2023|
Please also note that Microsoft has announced that it will no longer offer Windows support for PHP 8 and later versions. However, the PHP developers have already indicated that they are working on this, so Microsoft fans have nothing to fear.
Switching to PHP 8.0: How to succeed with the update
Set up PHP 8.0 individually
If you do not use Managed Hosting you can also set up PHP 8.0 individually. To do this, download the current version in advance. The further procedure depends on the operating system you are using:
- Debian und Ubuntu
For these Linux distributions, we recommend the packages from Debian maintainer Ondřej Surý https://deb.sury.org/, which we also use at maxcluster.
Linux distributions based on RPM can use the packages from Remi: https://rpms.remirepo.net/wizard/
For development environments under Windows, you can again use the packages from Ondřej Surý at WSL: https://docs.microsoft.com/de-de/windows/wsl/install-win10 oor you can create a simple development environment with XAMPP: https://www.apachefriends.org/de/index.html.
Set up PHP 8.0 at maxcluster
At maxcluster, PHP 8.0 is already available on all Ubuntu clusters. If you want to use it for your application, it is sufficient to activate the version for the vHost. If the application used has problems with this new version, the process can be reversed immediately.
You are still using one of our older Debian clusters and would like to use PHP 8.0? Then please contact our support team and we will check whether it is possible to switch to an Ubuntu 18.04 or 20.04 cluster. Our team will also be happy to support you with other questions and problems via e-mail to email@example.com or by phone at 05251/41 41 30.
With the new major release 8.0 of PHP, many new features and optimisations were released that bring performance improvements - above all the long-awaited JIT compiler. In this version, the developers have also focused on code constructs that support the writing of shorter, better structured and more readable code. Improved performance and shorter loading and access times are the positive consequences for online shops and justify the effort of an update to this version.
Published on 27.11.2020 | NM
Sie haben Fragen, Wünsche, Kritik, Anregungen oder wollen uns einfach mal Ihre Meinung zu unserem Blog mitteilen? Hier haben Sie Gelegenheit, direkt mit uns in Kontakt zu treten.E-Mail senden