PHP 7 is finally here, but is the hype deserved? The short answer is yes. For the slightly longer answer, we’ve put together seven things you can do with PHP 7 to demonstrate just how much of an upgrade it is.
1. Go twice as fast
Compared to PHP 5.6, PHP 7 offers up to twice the speed and 50% improved memory consumption. That’s quite the step up when you consider that PHP 5.6 is itself less than two years old.
But what does this mean in the real world? Imagine your website with PHP 7: it’s loading two times faster and serving up to three times more requests, and coping with more users at the same time. All this, while using the same server resources you had with PHP 5.6 – effectively boosting the performance of your hardware for free.
2. Push your apps harder
PHP 7 enhances the performance of the most popular CMS and eCommerce applications. In Zend benchmarks it was capable of three times as many Magento transactions when compared to 5.6 running on the same hardware. Zend also found that Drupal 8 runs 72% faster, and with WordPress, CPU instructions per request are reduced by 75%.
Overall, you can expect to see an average performance improvement of 20–70%, whatever apps you’re using. Keep in mind that you can benefit from increased performance just by upgrading to PHP 7, often without changing a single line of code. Of course, if you are writing new code and you’re looking for ways to up your game, PHP 7 also has you covered.
3. Tighten up shonky code
As much as you might enjoy coding, it can easily become a chore, and quality can suffer as a result. Wouldn’t it be great if there was a new version of PHP that took some of the hassle away, and encouraged you to write better code? By taking advantage of PHP 7, you can make your code faster to write, easier to follow, more efficient and more secure.
You could describe PHP 7 as ‘tighter’ than previous versions, with more opportunities to prevent page-breaking errors and fewer places for bugs to hide. For example, the new null coalescing operator helps to make common patterns of code easier to manage and ultimately more robust.
4. Upgrade your toolbox
What would a new version of PHP be without new features? PHP 7 doesn’t disappoint on this front, delivering a whole range of brand new features that provide everything you need to write higher quality, more cohesive code.
One of the biggest changes in PHP 7 is the introduction of scalar type declarations and return type declarations. These help you define functions and results more strictly and accurately – just don’t forget to enable them. The new anonymous classes also simplify code by removing the need to create whole new classes for one-off use.
5. Treat legacy code with respect
Nobody wants to update old code whenever they upgrade PHP, and generally speaking, you don’t have to. The vast majority of existing code will work perfectly with PHP 7, although it’s always worth checking that you don’t rely on any deprecated features or removed extensions.
For instance, old style constructors from PHP 4 will now cause E_DEPRECATED errors. Another big change is that the MySQL library from 5.5 has been replaced with new options. Visit PHP.net for a full overview of deprecated features.
7. Migrate with confidence
Migrating to PHP 7 from 5.6 or another previous version is simple, but there are a few basic steps you can take to ensure the process goes smoothly. For example, it’s a good idea to update your software across the board at the same time as PHP. By running the latest versions of PHP-related software, e.g. your CMS, you can minimise potential issues and take full advantage of everything PHP 7 has to offer. Testing your sites with PHP 7 before going live is also essential.
Another key consideration is the platform you use for your projects. If you want to run PHP 7, you’ll need a hosting provider that supports it, and not all of them do. Fasthosts offers full support for PHP 7 as well as 5.6, alongside the latest features and innovations for customers. Our Cluster Web Hosting platform is especially suited to running PHP 7, with a range of plans to choose from.
What happened to number six? Good question. PHP 7 is the first major release since PHP 5 back in 2004, with development of PHP 6 abandoned in 2010 due to numerous delays and performance problems. But don’t mourn PHP 6 too much, all the good stuff was backported into 5.3 and 5.4. And now, based on the PHPNG (PHP Next-Gen) project in the works since 2014, PHP 7 has arrived.