Powering over 76 million websites and holding a 59% CMS market share, WordPress continues to dominate the web in 2017. However, with the new year comes new challenges. Since PHP 7 could be the minimum requirement for running self-hosted WordPress in 2017, updating your server’s version of PHP to PHP 7 could be a necessary step.
In this post, we’ll cover why you should upgrade to the latest version, how to upgrade your server to PHP 7, any new features, inconsistency fixes, its overall performance, any backwards incompatible changes, the compatibility checker, and a note on PHP 7 benchmarks.
Let’s get started!
1. Upgrading WordPress to PHP 7
The arrival of PHP 7 brings big changes into view, including the latest PHPNG (Next Generation) engine and a host of powerful new features. It’s a good idea to upgrade your version of PHP if you want to keep your WordPress website running smoothly.
If you’re running a WordPress website then you already have PHP installed. Why should you upgrade its version when everything is seemingly running so smoothly?
- Minimum requirements. The minimum requirements for running WordPress are going to be bumped up soon; even as early as mid–2017.
- Security and stability. New updates often have patches for security flaws, and PHP is no exception to this.
- Plugin and theme compatibility. Plugin developers are going to update to the latest version, as well. Sooner or later the plugins you have installed won’t be compatible with the version of PHP you’re using. The same goes for WordPress themes and external scripts.
Of course, it does take time for developers to adopt new technologies. It’s likely that not all of your plugins, themes, and scripts will be compatible with the latest version once you upgrade. To review the changes beforehand, you can install the PHP Compatibility Checker.
You can upgrade WordPress to PHP 7 yourself via SSH, depending upon your server type. Alternatively, you can also get the job done by logging into your hosting provider’s cPanel and navigating to PHP Version Manager to choose the latest PHP version. That should be all there is to it!
2. New Features
We already know that PHP 7 is soon going to be a requirement for running WordPress. But why is that so? According to Matt Mullenweg, upcoming versions of WordPress are set to include functionality that relies on the latest version of PHP. Here are some new features we can expect to see.
PHP 7 comes with two new operators – the spaceship operator and the null coalesce operator. The spaceship operator is more commonly known as the combined comparison operator, and is essentially a combination of three individual operators. It works by checking the values with each operator individually. The spaceship operator is hugely beneficial for developers who find themselves having to create sorting algorithms. In addition, its basic working principle makes for blazing fast results.
Null coalesce (also called the if-set-or operator) is a simple way to assign a variable to the default value if it doesn’t already contain a value. It works by checking if the operand on the left holds some value. If it doesn’t, it returns the right operand. The best part about the null coalesce operator is that it’s stackable.
PHP 7 also comes with scalar type hints – int, float, string, and bool. These fundamental types make it easier to read code, and give the developer more control over variables. By default these type declarations are non-strict. However, using them is far easier if you enable strict requirements.
Lastly, the new technology also supports return type hints, which are specified with a colon followed by the return type. With this addition, you can be sure what a function will return, which makes it easier to test them out. From a developer’s point of view, these new type declarations force things to be how they are supposed to be.
3. Upcoming Inconsistency Fixes
PHP 7 will bring some much needed inconsistency fixes to the table. Perhaps the most beneficial development in this space is the addition of Abstract Syntax Trees (AST). These trees are used as intermediary representations of code during the compilation process. Abstract syntax trees can be used to write opcodes that are more performant. In addition, developers can clear up edge case inconsistencies. The key benefit here is that you don’t have to worry about being bogged down in concrete syntax issues.
In addition to the inclusion of abstract syntax trees, PHP 7 also comes with uniform variable syntax. The addition of this concept significantly reduces the number of inconsistencies that arise when expressions are evaluated. It ensures that references and expressions are accessed from left to right instead of right to left. With this, expressions which may have been invalid before would now be valid.
4. Boosting Overall Performance
One of the biggest reasons behind upgrading to the latest version of PHP is the massive performance improvements that it brings to the table. The significant improvement in performance is mainly attributed to the PHPNG engine. The latest PHPNG engine makes it just as fast (some argue even faster) than HHVM. According to the official benchmark results, most applications running on PHP 5.6 ran twice as fast on PHP 7. Here are some more statistics:
- The latest PHP 7 offers 50% better memory consumption than PHP 5.6.
- With PHP 7, you get 2x faster overall performance compared to its previous version.
- PHP 5.6 executes nearly 100m CPU instructions for a single WordPress request whereas PHP 7 only takes 25m CPU instructions.
Since the latest PHP version handles more than twice as many requests each second, developers can expect to see a 100 percent improvement in terms of performance on WordPress websites. In simple English, this means that your code will execute faster, and you’ll need a fewer number of servers to cater for the same number of users. These huge performance gains, in addition to optimized memory usage, gives developers strong reasons to make the switch.
5. Backwards Incompatible Changes
Still not sure whether you should upgrade to PHP 7? Let’s take a look at some things that could (potentially) break your site if you continue running it on an older version of PHP.
To establish some context to backwards compatibility, consider the following:
Code written a decade ago should run smoothly today and a decade from now.
As a developer, you can’t expect any language to conform to this, let alone PHP. Each new release brings with it some backwards compatibility and even more important, some backwards incompatibility, including:
- Deprecated items. A handful of deprecated items have been removed from PHP 7. Now’s a good time to go through the list and make sure you’re not using any of them. If you find a match, you can replace it easily with new tags and functions.
- Multiple default clauses. Multiple default clauses in
switchstatements do not cause warnings, which also make it difficult for developers to detect their mistake. PHP 7 introduces a detailed warning – Fatal Error: Switch statements may only contain one default clause.
- Engine exceptions. The current version of PHP displays fatal and recoverable fatal errors. PHP 7 replaces them with exceptions. Exceptions make it simpler for developers to identify the errors, log them, and take actionable steps to resolve them.
6. A Note on PHP 7 Benchmarks
By now you’ve probably heard that PHP 7 is fast over a dozen times. But how fast is it really?
PHP 7 running on the latest PHPNG engine is notably better than HHVM – in terms of both overall speed and memory optimization. From a purely WordPress perspective, benchmarks show that PHP 7 delivers impressive responsive times. A site that previously loaded in 1.2s on PHP 5.5 loaded in 4ms on PHP 7.
The performance benchmarks published by Zend’s Performance Team show that PHP 7 will not only execute your code faster but will also require fewer servers to serve the same number of users. WP Engine’s publication, PHP 7: The Way of the Future, provides an in-depth performance analysis of the new technology on WordPress. For even more information, Medium’s PHP MVC Framework Showdown: 7.0 Performance is incredibly detailed.
With PHP 7 being the minimum requirement for running a self-hosted WordPress site in 2017, it’s high time to get things in order and understand the upcoming technology. Let’s recap our checklist of things to know:
- There are good reasons to upgrade to PHP 7, and you can make the switch yourself through SSH or through your cPanel account.
- PHP 7 brings with it new operators and type hints that are set to ease development and make your code more readable.
- Abstract syntax trees and uniform variable syntax reduce the inconsistencies we saw in previous versions of PHP.
- PHP 7’s PHPNG engine may just be the biggest reason behind upgrading your servers.
- Be sure to run through our list of backwards incompatible changes before upgrading to PHP 7 to avoid any unprecedented pitfalls.
- The latest technology has some massive power running under the hood, which is arguably notably faster than HHVM.
Do you have any questions about how to get up and running with PHP 7? Let us know in the comments section below!
Image credit: OpenClipart-Vectors.