paint-brush
PHP 8: Features, Changes, Improvement, and What To Expectby@mobidev
664 reads
664 reads

PHP 8: Features, Changes, Improvement, and What To Expect

by MobiDevJanuary 19th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

PHP 8 was recently released, with all technical details listed here. As a Product Owner planning to start a new website or API written on PHP, what does PHP 8 mean for you? You can achieve a performance boost by upgrading through JIT (Just in Time) compilation. Your development team will be able to utilize a range of improved language features that make PHP better for enterprise-level projects. The good news is that the PHP core team continued their approach of prioritizing backward compatibility, just as they did in moving from version 5 to version 7.

Company Mentioned

Mention Thumbnail
featured image - PHP 8: Features, Changes, Improvement, and What To Expect
MobiDev HackerNoon profile picture

PHP 8 was recently released, with all technical details listed here. As a Product Owner planning to start a new website or API written on PHP, what does PHP 8 mean for you?

What benefits can you realize by upgrading an existing project to PHP 8? To briefly summarize, you can achieve a performance boost by upgrading through JIT (Just in Time) compilation.

In addition, your development team will be able to utilize a range of improved language features that make PHP better for enterprise-level projects.

Union types allow for the defining type validation, making the language closer to a strong typing approach. Note that this is an optional feature, allowing you to take advantage of both weaker and stronger typing depending on the situation in question.

PHP 8 offers many similar upgrades and improvements, but this article will focus more on the Product Owner’s point of view about what’s new in PHP 8.

History of PHP

Let’s walk through a brief overview of PHP’s recent history, which helps us understand its evolution over the years and how it came to introduce JIT compilation in version 8.

In the early days of PHP, its primary use was to simplify web development. PHP functioned as a template engine that allowed a user to select data in a database and render it dynamically to HTML.

PHP sought to avoid writing overly complicated projects in C/C++ and to lower the technical entry bar for web developers. Over time, PHP grew as a language, adding more features and eventually becoming more than a template engine.

By version 5, PHP had become a general-purpose web language with a huge community and a robust assortment of frameworks and libraries. Version 5 introduced powerful OOP support, allowing users to create structured, enterprise-level code written with the best SOLID principles.

Newer versions of PHP introduced the concept of frameworks, the most popular of which (Laravel) being developed as an alternative to old-school CodeIgniter.

Symfony-framework became a Java Spring enterprise framework of the PHP world, and PHP received tools like the package manager Composer and the unit-testing framework PHPUnit.

The next major version after PHP 5 was PHP 7 – Yes, they skipped PHP version 6. The core team chose not to introduce JIT-compilation, but made massive optimizations in the interpreter itself and managed to largely keep the language backward compatible (unlike the upgrade from Python 2 to Python 3).

PHP 7 introduced a significant performance boost, optimized RAM usage, and improved syntax, and was backward compatible with PHP 5 applications in most cases, with rare exceptions able to be brought into sync with PHP 7 within a reasonable timeframe.

Now, PHP 8 has introduced JIT-compilation along with numerous other PHP 8 breaking changes, a logical step for improving on version 7.

The good news is that the PHP core team continued their approach of prioritizing backward compatibility, just as they did in moving from version 5 to version 7.

Preparing for PHP 8: What does it mean for your existing applications?

Should you upgrade your production servers with PHP 8 tomorrow? Probably not. First of all, you should confirm that everything is working with PHP version 7.4. If that’s the case, your development team should familiarize itself with the migration guide.

Note that some elements are deprecated and will not work after upgrading to version 8. Keep in mind too that issues can arise not just with your own code, but also with dependencies.

It’s important to check whether your dependencies in composer.json support PHP 8. Additionally, you will need to upgrade your framework if you use one. Symfony framework 5.2 should already be compatible.

The same should be true for Laravel.

While you shouldn’t upgrade your production servers immediately, you should begin to allocate your development team(’s) toward researching the amount of time and effort it will take to eventually upgrade to version 8.

This will include looking into refactoring code with outdated and depreciated functions and approaches within your legacy code.

Even after your team is able to fix everything in need of updating, you should be performing a full testing regression of your system, as refactoring can often result in new bugs even in a project with adequate auto-test coverage.

Can you upgrade production after full testing is done? Yes, this is possible. But it’s advisable to wait for the next minor update version, which will have fixes for unnoticed issues in the new major version.

Make sure to measure your performance with the old setup and compare it with your new performance after upgrading, seeing which setup is optimal for your project.

In particular, you should check how enabling JIT will affect your application. It may or may not have a significant effect.

Although performance will not be affected in every case, JIT-compilation adds many opportunities for PHP in the future. JIT can enable potential use cases beyond the classic server-side web applications and may add more asynchronous programming features to PHP in future versions.

How to start a new PHP project

If you’re starting from scratch, you can begin with version 8. This reduces any costs associated with migrating from a previous version. While your team is working, new minor versions will be released, and you’ll be safe to move to production when ready.

New PHP 8 improvements will allow your team to write cleaner code, resulting in better performance from the start.

And keep in mind that the more code your team writes in older versions of PHP, the more migrating you’ll need to do when you choose to upgrade to version 8.

The most significant impediment to using PHP 8 would be if you know that you’ll have some dependencies incompatible with version 8 at your release time. However, this may be a sign that you ought to be thinking about replacing those dependencies anyway.

Conclusion

2020 has been a difficult year in many ways, but the release of PHP 8 has been a small silver lining.

Don’t miss the chance to upgrade your applications’ performance and improve the quality of your code-base through PHP 8 new changes.

Written by Alex Vasilchenko, Web Solution Architect at MobiDev.