PHP 7.3: The new features

Robert-Jan Budding, January 10, 2019

Early December, the newest version of PHP became available. It is the third feature update of PHP 7. Besides PHP 7.3, updates have also been released for older PHP versions (5.6.39, 7.0.33, 7.1.25, and 7.2.13). Given that WordPress and all themes and plug-ins are built with PHP, these types of feature updates are interesting to keep an eye on. 

We know that PHP 7.3 makes your websites faster than ever! What does the PHP 7.3 update entail further for WordPress websites?

No more support for PHP 5.6 and 7.0

PHP.net has (probably) released the last update for PHP 5.6: version 5.6.39 is a security release and does not contain any new features. The same goes for PHP 7.0.33. As of January 1st, 2019, PHP 5.6 will no longer be supported. PHP 7.0 is already no longer supported since early December.

Every version of PHP will be supported for two years, starting from the moment it is released. After those two years, the security of the PHP version will be supported for an additional year. This means that critical security issues will still be resolved.

PHP-versions-support

On the PHP website, you can see how long every PHP version will continue to be supported. As you can see in the screenshot above, PHP 7.1 will only continue to receive “Security Support” until December 1st, 2019. PHP versions 7.2 and the new 7.3 will both continue to be actively supported and updated. For PHP 7.2 this active support will continue until November 30th, 2019 and after that, it will receive one additional year of security support.

What does a PHP feature update entail?

A PHP feature update consists of two parts:

  1. New features or adaptations of existing features;
  2. Features that disappear, also called “deprecated” functions.

New features in PHP 7.3

PHP 7.3 gives developers a bunch of new features. We will give an overview of some of the most important changes. Both the WordPress Core team and theme and plug-in developers can use these features from now on! Developers do keep in mind that not all websites use the latest version of PHP, which is why they will continue to support older versions of PHP for some time.

Heredoc and Nowdoc

Some of the most important improvements in PHP 7.3 are the changes to the Heredoc/Nowdoc syntax. They were often despised by developers because there were quite severe requirements for the code. Due to these requirements, the use of the Heredoc and Nowdoc syntax could make the code ugly and less legible. In PHP 7.3 this problem is dealt with through two changes:

  • The “closing marker” may now have an “indent”.
  • After a “closing marker” it is no longer mandatory to begin a new line.

These changes for Heredocs and Nowdocs will make them more attractive for developers to use in their code. More on Heredoc and Nowdoc can be found in this blog of Laravel News.

JSON_THROW_ON_ERROR

This is not a core functionality of PHP, but it is an update of the JSON extension. JSON is a way to structure data, just like XML. It was cumbersome for PHP developers to work with error messages of the json_encode() and json_decode() functions, but PHP 7.3 is going to change that.

In PHP 7.2 and previous versions it went like this:

The line of code below tries to decode a JSON text. The text is “{“, which is not a valid JSON format. The code will therefore not work, but PHP 7.2 does not offer the developer information on why it does not work.

json_decode(“{“);

Afterward, you could use the following line to check if there is an error message:

json_last_error() === JSON_ERROR_NONE

Because there is an error – the syntax is not correct after all – the line above will return FALSE. To truly see the error, the following rule of code must be used:

json_last_error_msg()

This line will return a syntax error. In short: a cumbersome way to deal with error messages. The proposal to change this was approved by 25 votes to 0 and implemented in PHP 7.3.

What is new?

PHP 7.3 allows you to work with exceptions. The functions json_encode and json_decode now accept a new parameter: JSON_THROW_ON_ERROR, as shown in the example below:

try {
return json_decode(“{“, JSON_THROW_ON_ERROR);
} catch (
JsonException $error) {
$e->getMessage();
}

The aforementioned code does the same as before, but $e-getMessage() will return the value of json_last_error_msg() if json_decode fails. It is therefore a lot easier now for developers to deal with mistakes in coding and decoding JSON!

JSON applications in WordPress

JSON is used in WordPress in the WP API. This connection allows developers to have their application communicate with a WordPress installation.

Some examples:

  • WordPress Multisite – content of different installations displayed in one domain;
  • A custom web/mobile application to manage WordPress content;
  • Have a “smart” refrigerator post a WordPress post every day with the contents of the refrigerator at that time.

You can find more information on the JSON update in PHP 7.3 here.

Argon2 password hashing

Argon2 is a hashing algorithm that was introduced in PHP 7.2 as an alternative to the Bcrypt algorithm. The PASSWORD_ARGON2I constant can be used as follows in password_* functions:

password_hash('password', PASSWORD_ARGON2I);

Meanwhile, a new version of Argon2 has been released, so there are now three versions in total: Argon2d, Argon2i, and Argon2id. This last one is a type of combination of the first two and is thus the highest recommended for web use. This looks as follows:

password_hash('password', PASSWORD_ARGON2ID);

See also: Argon2 Password Hash Enhancements

Comma at the end of function calls

Every programming language deals differently with Variadic functions: a function with an undefined number of parameters. PHP 7.2 and older deal with this – calling functions – as follows:

getNumberOfClients( $company, $year )

It is not allowed to place a comma after $year: this would loop back a syntax error. Other programming languages are more flexible and PHP 7.3 also handles this more flexible:

getNumberOfClients( $company, $year, )

This is a pleasant improvement for developers because they no longer need to adapt this every time a function changes the number of parameters. This change only applies to commas when calling functions. When declaring functions, commas still cannot be placed at the end!

More new features

Of course, there are more new features in PHP 7.3. Everything about the new features and bug fixes can be found at PHP.net.

Deprecated in PHP 7.3

Likewise, there are features and functionalities that are “deprecated” in PHP 7.3. The features that are now deprecated will be removed completely from the code, no later than PHP 8.0. It is important that WordPress developers take a good look at this list and change the code of plug-ins and themes before these functions disappear. If you use PHP 7.3 on your WordPress website with a plug-in that calls a PHP 5.6 function that has been deprecated in the meantime, it will cause an error message.

Case-Insensitive Constants

In older PHP versions both “case-insensitive” and “case-sensitive” constants were supported. Case-insensitive constants are subject to inconsistencies and are difficult to use. That is why it was proposed in this RFC to no longer support this as of PHP 7.3.

image2wbmp()

The image2wbmp() function generates a WBMP version of an image. As of PHP 5.0, this function is identical to imagewbmp(), so this function will be deprecated starting from this PHP version. If you use image2wbmp() in PHP 7.3, you will be returned a deprecation warning.

What does PHP 7.3 mean for WordPress users?

According to the statistics on WordPress.org, only a small portion of WordPress websites uses a PHP version higher than 7.0. With over 35%, PHP 5.6 is still one of the most used PHP versions. PHP 7.3 is barely visible in the graphic but has a share of 0.1% of the WordPress websites.

PHP-versions-WordPress

It is unfortunate and worrisome that many WordPress users (and hosting parties) do not use the newer PHP versions, because PHP 7.3 brings a lot of improvements along with it. Much can be gained with PHP 7, especially when it comes to speed. For example, PHP 7 can process twice as many requests per second as PHP 5.6. On top of that, PHP 5.2 is 400% slower than PHP 7.

From the figure above it becomes apparent that 59% of all WordPress websites use PHP 5.6 or older. Earlier we wrote that PHP 5.6 is no longer supported as of January 1st, 2019. Older PHP versions have already not been supported for a longer time. It could be possible that PHP.net would still push a security update if a critical issue was discovered, but in principle, the support of PHP 5.6 is over. It is therefore important that WordPress websites switch to a more recent version of PHP, such as PHP 7.3.

How do I check the PHP version of my WordPress website?

You can check the PHP version of your WordPress website in the Savvii control panel. In the overview tab, you can easily change this to the latest version of PHP.

 

php7_admin_savvii

If you do not use our hosting services, you can check the PHP version of your WordPress website in the following ways:

  • Call the phpinfo() function;
  • Check the webhosting control panel.

Upgrade to PHP 7.3 at Savvii

Of course, you can upgrade to PHP 7.3 at Savvii. Everyone that still uses the older versions, 5.6 and 7.0, has received a message from us by now and can find a warning to update in the control panel.

Watch out: the old versions will definitively be removed at the end of January. We will transition your site to the new version ourselves, which may cause compatibility issues. So start working on updating the PHP version of your website as soon as possible!

Put your website on the staging environment first. In this environment, you can very easily test the new version without impacting the production site. Is everything working correctly? Convert your production website to the new PHP version. After a couple of minutes, our system has processed the change and your website is using the new version. You can use this guide to make a staging environment of your website.

If you want to speed up your website, read the 50+ other tips we have for you to speed up your website.

Also read: PHP updates (fall 2018)

Leave a reply