The PHP project announced the release of PHP 7.4 on November 28th, 2019. As usual, they have also published a migration guide to assist developers in updating their code to support PHP 7.4. This release continues to bring smaller gradual improvements to PHP just like 7.3 and 7.2 did, and it does not include drastic changes as 7.1 and 7.0 did.

Security improvements and speed optimization work have continued: PHP 7.4 is reported to be once again slightly faster than any previous release. Those alone are good reasons to consider upgrading to PHP 7.4. In addition, there are some new features.

Typed properties

In PHP 7.4 it is now possible to add extra validation to properties, e.g. variables in classes, to enforce that any code that calls them uses them properly. The notation is simple, just add the type in front of the property definition:

class User {
    public int $id;
    public string $name;

A null coalescing assignment operator

While PHP 7.0 introduced the ?? operator, this release now also has the ??= operator. This is handy to check that the value exists and then assign it in one line, instead of having to do separate isset() checks (or having PHP Notices emitted). Example:

$array['key'] ??= computeDefault();
// is roughly equivalent to
if (!isset($array['key'])) {
    $array['key'] = computeDefault();

Unpacking inside arrays

A new notation ... can be used to unpack an array. Consider the code example below:

$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', $parts, 'watermelon'];
// ['banana', 'orange', ['apple', 'pear'], 'watermelon'];

$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', ...$parts, 'watermelon'];
// ['banana', 'orange', 'apple', 'pear', 'watermelon'];

Numeric literal separator

Reading in the source code a value like 10000000 can be hard. Can you immediately spot if it says a million or 10 million or what? In PHP 7.4 you can have underscores (e.g. 10_000_000) in the value for readability without affecting how PHP uses the value.

More information about the changes in PHP 7.4 are available on the PHP website. Developers should also note the backward-incompatible changes and deprecated features.

WordPress 5.3 supports PHP 7.4

The WordPress core has official support for PHP 7.4 since version 5.3. It will, however, take some time before all plugins update to support PHP 7.4. There are also some PHP modules that are not yet available for PHP 7.4 (e.g. Tideways). Thus we do not recommend upgrading to PHP 7.4 just yet on production sites, but it would make sense to start doing it in early 2020.

Seravo will make PHP 7.4 available soon

Just like after previous PHP releases, Seravo has been very quick in making it available for our customers. The time frame is usually a couple of weeks after the official upstream release. We are still waiting for some PHP modules to become officially available for PHP 7.4 and will then start rolling it out into production, shadows and the development environments we provide (Vagrant and Docker).

At the same time, we will also introduce automatic PHP compatibility scanning for our customers’ code base and make sure all the tooling we provide will make it as easy as possible for developers to test and upgrade to PHP 7.4.

To be notified immediately when the tooling is available, we recommend subscribing to our developer newsletter.

Leave a comment

Read more

In category: Development

PHP 8.2 Soon Available

PHP 8.2 becomes available at Seravo for developer testing. However, we recommend using PHP8 on your live WordPress site – for now!

February 3, 2023

Upcoming PHP Updates at Seravo

Since 2022 PHP 8.0 has been the default PHP version at Seravo, and is automatically enabled on all new sites. PHP 8.1 is also available, and PHP 8.2 will be soon available for developers!

January 25, 2023

PHP 8.0 Enabled by Default

PHP 8.0 is the default version at Seravo’s premium WordPress hosting and upkeep. PHP 8.1 also available!

January 8, 2022

When the Internet Breaks – Make Sure Your Website Works

On Monday, October 4th 2021, something quite exceptional happened that did not go unnoticed by Seravo’s customers. Facebook and other […]

October 9, 2021

Webinar: Search Function and How to Customize It

Seravo’s first webinar of 2021 on January 14th: How to use and customize the WordPress search function?

December 30, 2020

What’s new in PHP 8?

On November 26th 2020, there will be a new version of PHP released. This new release has a number of new features, as well as implementing some non-backward compatible changes. Seravo has already started testing and deploying the release candidates of PHP 8.0 to our servers.

November 19, 2020