PHP 8.1 Available on All Servers

December 2, 2021

PHP 8.1 was recently released and has been rolled out to all ServerPilot servers today. PHP 8.1 includes several new features, as well as some performance improvements. Continue reading to learn about the highlights in PHP 8.1.

To read about all of the changes in PHP 8.1, check out the announcement​​ on the official PHP site.

PHP 8.1 Changes

Enums

Enums are a long-awaited feature in PHP. Enums are a collection of values that your classes can implement. They can be untyped (pure enums) or typed (backed). Backed Enums are useful if you need the values to be serialized into a database.

Enums should help PHP developers maintain consistent use of data across their application and libraries.

Readonly Properties

Readonly properties are a way to ensure that an object's internal properties cannot be changed once set. This means a whole category of data changes can no longer occur. By marking a class' public property as readonly, it's locked in. Any code that tries to change that property will throw an error.

Final class constants

Normally, class constants can be overwritten during inheritance. In PHP 8.1, you can prevent this by marking a constant as final. This is another way that PHP 8.1 helps protect an object's data against unintentional changes.

Performance Improvements

PHP 8.1 brings opcache improvements with an "inheritance cache." In PHP 7.4 linked classes could be cached, now in 8.1 the links between classes can also be cached. This change may bring noticeable improvements to some PHP applications.

How to Switch to PHP 8.1

You can change an app to use PHP 8.1 through your app's Settings in ServerPilot. If your app does not work with PHP 8.1, you can easily change back.

As always, please contact us if you have any questions.

PHP 8.1 is only available on servers with Ubuntu 16.04 and later.