PHP 8: Check Out The New Features in The Latest Version

agnes john
5 min readJun 22, 2021

--

PHP 8, the latest version of PHP, was officially released on November 26, 2020. It is the latest version of PHP updated in February 2020. It comes with advanced security, which is more than PHP 7.4 and older versions. Additionally, it has fixed major issues and comes with performance improvements for WordPress sites.

As a product owner starting a new website or API written on PHP, what does the update to PHP 8 mean for you? What benefits can you derive by upgrading an existing project to the latest PHP update? Let’s find out.

In this article, we will discuss some of the major features, trends and shortcomings that PHP 8 comes with and how it will affect the industry.

History of PHP

Let’s go through a quick overview of PHP’s recent history. This will help us get an idea of its evolution over the years and how it came to bring in JIT compilation in PHP 8.

In the initial days of PHP, its main use was to simplify web app development. PHP functioned as a template engine that let a user select data in a database and render it dynamically to HTML. PHP sought to avoid writing overly complicated projects in C and C++ and also to reduce the technical entry bar for web developers and PHP development services. Over time, PHP developed as a language, adding extra features and consequently becoming something more than a template engine.

PHP had become a general-purpose web language by version 5 with a huge active community of PHP development services and a versatile assortment of libraries and frameworks. This version introduced strong OOP support allowing end-users to create enterprise-level, structured code written with the best solid principles.

The newer versions of PHP introduced the idea of frameworks — the most popular of which (Laravel) was later developed as an alternate option to CodeIgniter. Another popular Java Spring enterprise framework of the PHP world was Symfony-framework. Over the years PHP development services received tools like the unit-testing framework PHPUnit and the package manager Composer.

The next important version after PHP 5 was PHP 7. The 5core team made massive optimizations in the interpreter itself but chose not to introduce JIT-compilation until PHP 8. They managed to keep the language backward compatible (unlike the upgrade of Python 2 to Python 3).

PHP 7 came with a major performance boost, improved syntax, optimized RAM usage and was backward compatible with most PHP 5 applications. Some rare exceptions were brought into sync with PHP 7 in a small timeframe by most PHP development services.

Now PHP 8 has come up with JIT-compilation along with several other improvements. The good news is that the core team of PHP continued their approach of giving priority to backward compatibility — just as they did with the movement from version 5 to version 7.

PHP 8 Features

You can see the entire list of features here. Let’s check out the major features among those.

Just-In-Time compilation — this is one of the most acclaimed features of this update. PHP 8 brings in 2 JIT compilation engines. Tracing JIT displays about three times better performance on synthetic benchmarks and around 1.5–2 times improvement on some long-running applications. The application performance is on par with PHP 7.4.

Error handling and type-system improvements — PHP 8.0 comes with strict type checks for bitwise/arithmetic operators RFC. This includes (1) Correct signatures of magic methods (2) Abstract trait method (3) Fatal error for an incompatible method (4) Reclassified engine warnings (5) Inheritance with private methods (6) Static return type (7) Mixed type (8) Types for internal functions email thread — opaque objects instead of resources for OpenSSL, Curl, XML Writer, Gd, Sockets and XML extensions.

Improvements in PHP 8

Compared to PHP 7.3/7.4, PHP 8 is faster. Almost 65% of the websites on the internet support PHP. Some important names in that list include Wikipedia, Facebook, WordPress etc. The major improvements featured in the latest version include:

· Union types

· Named arguments

· Constructor

· Constructor property promotion

· Match expression

· JIT

· Error handling

· Null-safe operator

· Better performance

· Improvements in the type system

· Type safety and better syntax

· Consistency

· A trailing comma in parameter lists RFC and closure use lists RFC

· Variable Syntax Tweaks RFC

· Non-capturing catches RFC

· Throw is now an expression RFC

What does the upgrade mean for your existing applications?

So, should you go ahead and upgrade your production servers with PHP 8 immediately? Probably not. First, you should ensure that everything is working perfectly well with the existing PHP version. If yes, then your development team can familiarize themselves with the PHP migration guide.

Please note that some components are deprecated and may not work after the upgrade. Also, keep in mind that some issues can arise with your codes as well as your dependencies. It is also necessary to check whether your dependencies in composer.json support PHP 8. If you currently use a framework, then you may have to upgrade that as well.

While you don’t have to upgrade your production servers instantly, you should initiate the allocation of your PHP development services team towards researching the amount of effort and time it will take to upgrade to the latest version. This means they need to look into refactoring code with the depreciated and outdated functions and approaches in your legacy code.

Even after your team has fixed everything in need to update to PHP 8, you should be performing a full testing regression of the system since refactoring can sometimes result in new bugs even in a project with enough auto-test coverage.

Is it possible to upgrade production to PHP 8 after complete testing is done? Yes, that is possible. However, it is recommended to wait for the next minor update version which will include fixes for issues that went unnoticed in the latest version.

Also, make sure that you measure your performance with the previous setup and make a comparison with the new performance after upgrading to PHP 8. Find out which setup is optimal for your project. Particularly, you should check how enabling JIT will make an impact on your application. While it may have a serious effect, it is also possible that it does not make a significant change.

Although performance may not be affected in every instance, JIT compilation provides many opportunities for PHP development services in the future. JIT enables potential use cases that go beyond the classic server-side web apps and may eventually add more asynchronous programming features to the future versions of PHP.

Summing Up: Are we ready to embrace the changes with PHP 8?

We hope that you were able to get a summary of the major changes that are introduced in PHP 8. As we had mentioned above, remember that you should consider updating your application after testing and once a stable version is available with your hosting provider. PHP progresses gradually. Therefore, before you explore the one at hand, a new version might become available with updates. Also, make sure you rely on competent PHP development services for guidance and web application development.

--

--

No responses yet