PHP 8.0 – what’s new

Stephen Evans
Tuesday 25 May 2021

PHP is used on the University website to provide dynamic web content, sometimes to bring content from an external database or from an external feed such as news or events. Each release of PHP is fully supported for two years. After each two year period, the version is supported for an additional year to only fix critical security issues.  With each release, there is the deprecation of existing features and the introduction of new ones. What can we expect from PHP 8.0?

PHP history

The following figure from the PHP website shows the current releases of PHP. Version 9 was released in November 2020 – it can be seen that the University will soon need to plan to move to PHP 8 as active support for PHP 7.4 ends this year.Graph showing history of PHP versions

There are very good websites that go into details about the changes between each version. This article will just highlight a few notable changes.

PHP 8.0 new functions

A notable function is the new str_contains() function. Instead of this:

if (strpos('string with lots of words', 'words') !== false) { /* … */ }

You can now do this:

if (str_contains('string with lots of words', 'words')) { /* … */ }

There is also the new str_starts_with() and str_ends_with() functions:

str_starts_with('haystack', 'hay'); // true
str_ends_with('haystack', 'stack'); // true

PHP 8.0 reclassified warnings

Lots of warnings and notices are now errors. This means that there is a chance that old code will no longer run until it is fixed. For example, if a variable is undefined, this would have given a notice warning, but now it will give an error and stop working. For more details see What’s new in PHP 8 on Stitcher.

PHP 8.0 performance improvements

PHP 8 introduces the Just in Time compiler (JIT). As PHP is an interpreted language, this means that when a PHP script runs it has to be complied and executed every time the code is requested. The JIT compiler makes the process of compilation a lot more efficient by bypassing some of the steps. The following figure shows the possible improvements:

PHP 8 performance diagram

The performance tests suggest that WordPress is not actually going to benefit much from the JIT implementation. For further details see PHP JIT (Just in Time Compiler) on Kinsta

PHP 8.1

The next release of PHP 8 is due in November 2021. This introduces further performance enhancements that will give a 5 to 8% improvement.

Conclusion

PHP 8 will provide some important improvements, but the University will have to plan to take time to test the current code before making the switch. It is likely that older code will need major updates before it can be transitioned.

Related topics

Share this story