What’s New in Php 8

What’s New in Php 8

PHP 8.0, a major update of the PHP language, has come with many new powerful features, and optimisations. Released in November 2020, the new update features interesting changes and performance improvements. Some interesting features include the union types, JIT compiler, attributes, and named arguments among others.

PHP powers a significant portion of websites and applications today. If you have not kept your client’s sites updated with the latest releases there’s a chance you may have to make some changes to your code. Our team at Codeias can help you make the necessary changes so your clients can enjoy all the benefits that come with the latest PHP version.

New Features in PHP 8.0

 

Just in Time Compiler

The JIT compiler is one of the most acclaimed features of the new PHP 8.0 update. The new update features two JIT compilation engines. Compiled language involves converting computer-readable code ahead of time. PHP features an interpreted language which means the source code is converted as it is executed.

The addition of the JIT compiler speeds up performance by compiling and caching some sections of code at execution. The compiled version can then be used in place of the interpreted version which leads to major performance gains.

The JIT compiler is particularly useful for CPU-intensive applications such as large mathematical computations or 3D rendering. The compiler is not enabled by default.

 

Attributes

Also known as annotations, attributes mainly allow declaring meta-data for functions, properties, classes, and parameters. Before PHP 7.4, doc-comments were used to add metadata to declarations of functions, classes, and more.

Attributes v2 makes it easier to declare annotations, store them in Docblock, and parse the string to infer them. Attributes v2 is structured metadata that allows developers to use it with PHP native syntax.

 

Union Types

Another major improvement that comes with PHP 8.0 is that it supports union types. Developers can now assign multiple types or values to variables similar to TypeScript. Before PHP developers had to specify the combinations of types in PHPDoc annotations.

Union types can be two or more types indicating that either of them can be used.

 

Named Arguments

PHP 8.0 named arguments allows developers to pass arguments to a function by adding its parameter name before the value. Using the parameter name instead of the parameter position makes the code easier to understand because it is more descriptive.

Named arguments also allows developers to specify required arguments without specifying default ones.

 

Starting a New PHP Project

Developers starting from scratch can start with version 8 to reduce costs associated with migrating from older PHP versions. The new PHP improvements allow developers to write code that results in better performance.

It is important to note that as you work, it is likely that new minor PHP versions will be released and the more code written in older versions, the more migrating there will be when upgrading to version 8.0.

If you have any problems using PHP 8.0, there are likely some dependencies that are incompatible with the new version. However, it is also a great indicator that you should start working on replacing the dependencies that are holding you back in preparation for future updates.

 

Contact us on 01257 758 078 or email us at enquiries@codeias.com to find out more about PHP 8.0 and how your clients can benefit from this upgrade.