PHP 7

Why Should You Upgrade to PHP 7?

Developers running PHP-enabled websites such as WordPress, Drupal, Joomla, or Magento along with PHP frameworks like Laravel and Symfony should stay up-to-date with the latest version and trends in PHP. Upgrading your site to PHP 7 will ensure you get all the latest benefits and security. Learn about the benefits of PHP 7 and how to get it up and running on your website.

Usage

About 98% of websites are still using PHP version 5.*. With PHP5 being more than 11 years old now, it’s time to upgrade to PHP 7 and clean up those obsolete functions. The PHP project has a list of deleted functions as well as a list of removed APIs and extensions, which will guide you in porting PHP 5 to PHP 7 code.

Most big blog systems such as WordPress, content management systems (CMS) like Joomla, and e-commerce sites like Opencart support PHP 7 out-of-the-box. Make sure you’re running the latest version of WordPress or your CMS and switch your webserver to PHP 7. Many services updated automatically to stay on top of new releases and trends. If you are unsure what version of PHP you’re running, contact your web hosting company. Many video tutorials are available to guide you through installing or upgrading to PHP 7.

History

In the beginning of 2015 the first alpha of PHP 7 has been released. The first stable (v7.0.0) PHP was released December 1, 2015. Currently, the PHP community is busy with version 7.0.8 (release candidate) and 7.1.0 alpha. PHP version 7.0.7 is released as stable. Most important issues have been resolved, and PHP 7 is mature enough to use in production.

What about version 6? PHP 6 was never released, although it was in originally in development. The idea was to introduce Unicode in PHP 5, calling it PHP 6. Unicode is a computing standard for the encoding and representation of text. Due to the complexity of introducing Unicode, PHP 6 was never released. Unicode doubled the memory consumption and impacted the performance due to conversions, and PHP 6 was abandoned. Moving forward, it was decided the newest version of PHP would be named PHP 7 while skipping PHP 6 altogether.

Performance

One of the biggest reasons to switch from PHP 5 to PHP 7 are the speed improvements. See the benchmarks below for comparisons of Drupal and WordPress measurements (higher bars are better performing):

 

 

PHP 5 vs PHP 7 website (2x faster!)

Another comparison of PHP versions as well as HHVM (a virtual machine for PHP) in req/sec (again higher is better).

Another comparison of req/sec.

PHP 5.6 vs HHVM 3.11 vs PHP 7.0.

Response time between PHP 5, HHVM and PHP7 (less is better).

Response time between PHP 5, HHVM and PHP 7.

Response time between PHP 5, HHVM and PHP7.

Last but not least, a comparison between PHP 5, HHVM, and PHP7 memory usage with RAM in megabytes (less is better).

Memory usage PHP 5, HHVM and PHP 7

Memory usage PHP 5, HHVM and PHP 7

What is new?

  • Improvements in performance! PHP 7 is twice as fast as PHP 5.6.
  • Significantly reduced memory usage, as we have seen above.
  • Abstract Syntax Tree (AST) data structure used for the PHP 7 compiler.
  • Consistent 64-bit support
  • Improved Exception hierarchy
  • Many fatal errors are now converted to Exceptions
  • Secure random number generator
  • New operator: null coalescing (??) that returns the result of the first operand if it exists & not NULL, or else its second operand.
  • New operator: spaceship (<=>) that returns -1, 0 or 1 when the first operand respectively is less than, equal to, or greater than the second operand.
  • Anonymous classes: a class that does not contain a name can be used when the class does not need to be documented or is used only once.
  • Use define() function for defining array constants (before only const could be used).
  • Scalar Type declarations allow functions to require parameters of a certain type at run-time.
  • Return Type declarations allow functions to return a specified type.
  • And much more…

Download

You can download the latest PHP 7 version from the official website.

If you have a Debian server running with PHP, try-out Dotdeb.org, which provides up-to-date packages (32bit & 64 bit) for Debian servers. It includes Nginx and MySQL as well as PHP 7!

Depending on your GNU/Linux distribution, PHP 7 may already be available in your package manager. Video tutorials are often available to help upgrade PHP for your specific distribution.