If you are not using PHP 7 yet, you should be

PHP 7.2 came out in November 2017 and 7.0 was launched nearly 2 years prior.  2016 was a sort of “burn in” period for PHP 7.  We saw popular open source libraries work to be compatible and early adopters use it for new projects and side projects.  In 2017 we saw lots of folks embrace PHP7 on larger projects including us.

It’s 2018 now, what are you waiting for?  If you aren’t using PHP 7 you should be!

New features in 7

Modern frameworks are embracing 7 as well as enterprise apps.  It’s now considered stable and mainstream.  Lets take a quick look at the new features in 7 that are inspiring this embrace.

  • Scalar type declarations
  • Return type declarations
  • Spaceship operator
  • Filtered unserialize()
  • Expectations
  • Session options
  • Nullable types
  • Void functions
  • Symmetric array destructuring
  • Multi catch exception handling
  • Support for keys in list()
  • Asynchronous signal handling
  • HTTP/2 server push support in ext/curl
  • New object type (for type declarations)
  • New encryption library: Sodium

Performance improvements

  • 2x Speed improvements over PHP 5
  • Less memory usage
  • Folks are seeing overall performance increase 25%-75% without changing any code
  • Performance and general improvements to curl, openssl, closures, PDO, and LDAP

Support for PHP 7

The latest versions of these frameworks and platforms support PHP 7 and in many cases require version 7.0 or higher.

  • Magento 2
  • WordPress
  • Drupal 8
  • Laravel
  • Symfony
  • Slim

Should I use version 7.1 or 7.2?

If you are starting a new project and your framework supports 7.2 start with 7.2.  It’s a great starting point for fresh apps.

If you are migrating a legacy app and your new (or upgraded framework) supports 7.2 then you should weigh the time needed to update the custom code to 7.2.  If it is a later version of PHP 5 it’s worth migrating the code.  In many cases very little code will need to change.  If you are using a deprecated feature set you may need to spend more time upgrading that feature or removing libraries in favor of new ones.

For Magento 2, you should run 7.1.  As of earlier this year I had difficulties running with 7.2.  There were a few deprecated libraries including mcrypt, still being used.  I hope it will be 7.2 compatible later this year.

If you are running out of the box WordPress use PHP 7.2.  If you are running the latest version of WordPress but have a lot of 3rd party plugins you will need to check to see if they are compatible.  You could see a ~20% improvement in performance (reference).

Conclusion

It’s time to upgrade to 7 if you haven’t already.  PHP 7 has far greater performance, security and lots of new features for your team to explore.

BTW If you are using mcrypt, stop, switch to OpenSSL or Sodium.  Mcrypt was a very handy package years ago, but it no longer maintained and is clunky.

Additional resources links

https://torquemag.io/2017/12/wordpress-developers-need-know-php-7-2/
http://blog.teamtreehouse.com/5-new-features-php-7
http://php.net/manual/en/migration70.new-features.php
http://php.net/manual/en/migration71.new-features.php
http://php.net/manual/en/migration72.new-features.php

Next Post

Comments

See how we can help

Lets talk!

Stay up to date on the latest technologies

Join our mailing list, we promise not to spam.