PHP 7 Inside Out by Arkbauer

PHP 7 – the most dramatic update to the language in over a decade has arrived. Released in December 2015, PHP 7 offers huge performance gains for websites and online applications. There are some significant differences between PHP 7 and the previous version of the language.

What Drove the Need for PHP 7?

PHP is an extremely popular programming language that powers around 83% of websites, which means that most of the Web today relies on the PHP language.

Significant changes to the PHP core have dramatically increased the performance of sites and applications that use the language. Even before PHP 7 was officially released Rasmus Lerdorf, the father of PHP, applauded the incredible performance gains compared with PHP 5.6 during his presentation at the O’Reilly Fluent conference in San Francisco.

Another motivation for the development of PHP 7 was the need to develop scripting languages that run more efficiently to reduce hardware costs. Facebook’s success with HHVM also played a role here. PHP 5 was not even close to HHVM but PHP 7 is its equal. There are several benchmark results showing that HHVM is still faster. However, results can go either way depending on the hardware and software used to perform the benchmark comparisons.

But Wait, Where Did PHP 6 Go?

You might wonder what happened to PHP 6, why the skip from PHP 5 to PHP 7? The short answer is it was a failure. The main feature of PHP 6 was native support for Unicode characters since PHP is used mainly in web development and the web needs Unicode, so the move to bring Unicode to PHP made sense. Since several books and articles had already been written about PHP 6 and its Unicode support, the new version was renamed PHP 7 to avoid confusion.

What’s New in PHP 7?

PHP 7 provides several new features compared to its predecessor PHP 5. It’s a pretty extensive list so I won’t repeat it here. Instead, I suggest you read them from the official PHP.net website.

Even though you might not need all the new features PHP 7 has to offer, you will definitely want to get the speed and performance benefits it provides. If you dare, go ahead and take a look in low level details of PHP 7 memory enchantments that Nikita Popov shared during his speech at IPC15.

How Do I Upgrade to PHP 7?

The first question that you might want to ask is should I upgrade in the first place? There is no right answer to this question, however. The PHP development team encourages everyone to upgrade to latest stable release. You might want to take a look at the currently supported PHP versions to understand how much longer you can postpone if you are still using outdated and unsupported PHP versions. Keep in mind that bugs and security vulnerabilities are found even in very old software. We (Arkbauer) always suggest you upgrade to the latest stable release of any software. We believe it’s the best way to avoid potential problems in the future and most likely to save you time, money and safeguard your reputation in the long run.

PHP 7 is the most significant update that has affected the PHP scripting language in more than a decade therefore upgrading your existing code might not be so easy.

First, you will need to make sure that all libraries used in your project are available for PHP 7. If the libraries do not yet support PHP 7, you may have to delay upgrading for a while, or see if it is possible to remove dependence on those libraries.

If your code is written in PHP 5.5 or PHP 5.6, then upgrading is likely to be quite easy. However, if you use PHP 4, then there are several syntax related changes that you should be aware of. For example, the old style of constructor functions from PHP 4 is not supported in PHP 7, even though it works in PHP 5. In some cases you might want to divide upgrading into several stages e.g. PHP 4 to PHP 5 and only then to PHP 7.

To save time and the hassle of searching for all the incompatibilities in your existing code you should use some automated tools like PHP7MAR (Migration Assistant Report), PHP 7 Compatibility Checkerphp7ize or Phan. Note that they can only outline issues found in static code – You will still need to make sure dynamic code parts are compatible with PHP 7, unit tests can help with that.

Also you can use predefined PHP7 Vagrant box to test your application and get you started.

In Conclusion

PHP 7 is a major upgrade compared to the last stable version – PHP 5.6. Even though upgrading your code to PHP 7 involves carefully checking for incompatibilities, both in your code and in any libraries on which your code depends, the benefits of upgrading to PHP 7 really pay off. PHP 7 performs much faster than any previous version, which allows sites that use the new version of the language to offer much better service to their users and save costs at the same time.

Let's Talk
First name
Last name
Phone
Phone number entered is invalid.
Message*
Message must not be empty.
preloader