PHP 8: release features and improvements

Release PHP 8 (PHP major update)

The last version of the PHP language, PHP 8, was released on November 26, 2020. This last major update includes many new features and significant optimizations, compared with previous versions. The development of the 8th version of PHP has been focused on creating new functionalities. Named arguments, attributes, constructor properties and JIT are some of its new major features.

Named arguments

Named arguments are order-independent and self-documented, and enable skipping optional parameters. They allow naming parameters when calling a function; a feature already exists in other programming languages. 

Named arguments enable developers to just overwrite the default values they wish to change. This way, there is no longer need to specify all the default values. Besides, named arguments can be combined with normal, positional arguments.

JIT: Just-In-Time Compilation

As part of the improvements in performance, PHP 8 includes two JIT compilation engines: Tracing JIT and Function JIT. Typical application performance is similar to the previous PHP version, but performance for CPU-intensive applications is boosted. As explained in the JIT PHP RFC:

“Using JIT may open the door for PHP being more frequently used in other, non-Web, CPU-intensive scenarios – where the performance benefits will actually be very substantial – and for which PHP is probably not even being considered today.”

JIT compilation, also known as “dynamic translation”, is a useful technique to significantly improve performance. It consists of executing computer code that’s directly compiled during the execution of a program; it is to say, at run time instead of before the execution.

Attributes

This new feature allows adding structured metadata directly with PHP’s native syntax; without using PHPDoc annotations. Attributes can be applied to classes, functions, interfaces. etc. A similar concept to attributes already exists in other programming languages.

Union types

Union types allow moving more type information from PHPDoc annotations to function signatures. Supporting union types directly in the language brings diverse advantages, such as: significantly simplifying and optimizing the syntax, minimizing the risk of type information becoming outdated and early mistake detection. Nevertheless, arbitrary union types aren’t supported for now.

Further features of PHP 8

PHP 8 includes further features such as the constructor property promotion RFC, match expressions or the nullsafe operator. It also includes type system and error handling improvements, such as: static return type, reclassified engine warnings or stricter type checks for arithmetic and bitwise operators.

This new version also includes new functions, classes and interfaces, such as: token_get_all(), get_debut_type(), a weak map class or a new stringable interface.

You can find further details, examples and documentation about PHP 8 on its release webpage.

Share it on Social Media!

Cookies customization
Stackscale, Grupo Aire logo

By allowing cookies, you voluntarily agree to the processing of your data. This also includes, for a limited period of time, your consent in accordance with the Article 49 (1) (a) GDPR in regard to the processing of data outside the EEA, for instead, in the USA. In these countries, despite the careful selection and obligation of service providers, the European high level of data protection cannot be guaranteed.

In case of the data being transferred to the USA, there is, for instance, the risk of USA authorities processing that data for control and supervision purposes without having effective legal resources available or without being able to enforce all the rights of the interested party. You can revoke your consent at any moment.

Necessary Cookies

Necessary cookies help make a web page usable by activating basic functions such as the page navigation and the access to secure areas in the web page. The web page will not be able to work properly without these cookies. We inform you about the possibility to set up your browser in order to block or alert about these cookies, however, it is possible that certain areas of the web page do not work. These cookies do not store any personal data.

- moove_gdpr_popup

 

Analytical cookies

Analytical cookies allow its Editor to track and analyze the websites’ users behavior. The information collected through this type of cookie is used for measuring the activity on websites, applications or platforms, as well as for building user navigation profiles for said websites, application or platform, in order to implement improvements based on the analysis of data on the usage of the service by users.

Google Analytics: It registers a single identification used to generate statistical data about how the visitor uses the website. The data generated by the cookie about the usage of this website is generally transferred to a Google server in the USA and stored there by Google LLC, 1600 Amphitheatre Parkway Mountain View, CA 94043, USA.

- _dc_gtm_UA-XXXXXXXX-X

- _gat_gtag_UA_XXXXXXXX_X

- _ga

- _gcl_au

- _gid