PHP 8.0 is now available, with a JIT compiler and many new features in its syntax

Few months after PHP turned 25, its version 8.0 has just been released. PHP continues to be the most widely used programming language on the Internet when it comes to generating dynamic web pages (it is behind 79% of them), despite the strength of technologies such as Node.js or ASP.NET.

The previous version of PHP, 7.4 (which will continue to receive support until December 6, 2021) contributed notable performance improvements, a section in which 8.0 will also stand out. But this is accompanied by many more news:

JIT compiler

Without any doubt, the main novelty of PHP 8 is the introduction of JIT compiler (Just in time), which will allow you to compile certain parts of the code on the fly, at runtime.

This functionality, which was about to be included in version 7.4, has been in development for years and supposes a big change for the PHP ecosystem.

When you update your current PHP installation, the JIT compiler will appear disabled by default, but it can be enabled from the file php.ini, will allow to store the native code of the PHP files in an additional region of the shared memory OPcache.

17 developers tell us which programming language they would choose to start from scratch and why

Preliminary tests confirmed that activating the JIT compiler allows quadruple the performance of some types of tasksespecially those that demand a lot of CPU resources.

The truth is that from this, rather than benefiting the classes of web applications typically linked to PHP (such as, for example, Wordpress), what it does is above all open new possibilities for PHP as a general-purpose programming language, allowing it to be used in fields such as machine learning.

Other changes

PHP 8 also incorporates several small but relevant changes at the syntactic level, such as:

  • The introduction of named arguments, which frees us from matching the order of the parameters with the parameter list of the methods used.

  • Automatic property propagation: Currently, when we want to define a property in PHP, we are forced to repeat it up to three times before starting to use it. But this new feature allows us to significantly reduce the amount of code used:

Screenshot 24

Before and after.

  • Support for union types: Before PHP 8, we could only specify union types using PHPdoc annotations, but the new version will add support for union types in function signatures, again saving us quite a bit of code.

  • Match expression: PHP incorporates a new match expression similar to switch, but with more secure semantics, as well as the ability to return values.

  • New operator nullsafe: Currently, when we wanted to check in PHP that a getter did not return null, we were forced to nest successive ifs. But, from now on, the first getter to return null will abort the entire chain execution:

Screenshot 25

Before and after.

  • Expression throw: So far in PHP throw it was a declaration, so it was not possible to use it in places where only one expression was allowed. From now on, however, it will be considered an expression.

Via |