PHP 7.1 Already Available on Our Servers

We are thrilled to announce that one more time SiteGround has made the latest PHP version (PHP 7.1) available on most of its servers just minutes after it was officially released. PHP 7.1 comes with exciting new features for developers. However, it also reintroduces incompatible changes and migrations from 7.0 to 7.1 should be performed with great caution.

In this blog post we would like to:

  • Introduce some of the major changes and new features in PHP 7.1
  • Provide information about the current state of WordPress, Joomla! and Drupal in regard to PHP 7.1
  • Provide information on how to use PHP 7.1 on our hosting servers

Our favorite PHP 7.1 new features

Тhe official PHP 7.1 documentation provides info about all the new features and changes. Here we would only mention our top 3 favorite things about PHP 7.1.

1. Catching Multiple Exception Types. One problem which many developers encounter is that they have to copy and paste code when they want to catch and handle exceptions of different types but use the same code to do this. Here is a simple example:

<?php

 

try {
// Just some code…
} catch (Exception1 $e) {
// Some code to handle the exception
} catch (Exception2 $e) {
// Same code to handle this different exception
} catch (Exception3 $e) {
// Some other code…
}

It is obvious from the example that in this case devs will need to copy and paste code and also the code doesn’t look clean and beautiful. With PHP 7.1 you can do the following to catch multiple exceptions and handle them:

<?php

try {
  // Just some code…
} catch (Exception1 | Exception2 $e) {
  // Code to handle the exception
} catch (Exception3 $e) {
  // Some other code…
}

This looks much better and allows us to catch multiple exceptions.

2. Nullable Types. PHP 7.0 introduced the type-declaration mechanism and we loved it. However, we had the feeling that it would be great to declare a parameter, indicate it could be “null” and at the same time make this optional. This is now possible in PHP 7.1. The following code was not working in PHP 7.0:

function func01(int $g) {
var_dump($g);
}

 

func01(100); // int(100)
func01(null); // TypeError

The second time we call the function PHP 7.0 will return an error message because “null” is not supported and the function expects an integer. In order to fix this code we had to use if statements to check if the function is passed “null”. PHP 7.1 resolves this issue very elegantly and in order to achieve our goal we just need to modify the function and add a single question mark in the beginning of a type’s name:

function func01(?int $g) {
var_dump($g);
}

This means that null is optional. Nice!

3. The mcrypt library has been deprecated. Everyone knows that if you’re typing mcrypt and adding it to your code then you are doing it wrong and you have to check and replace your code in favor of OpenSSL. Still, we love the fact that mcrypt has finally been deprecated and soon will completely be removed. This way PHP now forces new developers to use OpenSSL instead of mcrypt.

PHP 7.1 and adoption among the most popular content management systems

We have tested the three most popular content management systems (WordPress, Joomla! And Drupal) and the results are the following:

  • Currently, WordPress 4.6 is not PHP 7.1 compatible. WordPress 4.7 which is scheduled to be released on Tuesday, December 6 is fully compatible with PHP 7.1 and it works as expected.
  • Joomla! version 3.6.4 works as expected with PHP 7.1
  • Drupal 8.2.3 also works as expected with PHP 7.1

Please note that we tested just the core of the above mentioned applications. Any modules and plugins that you are using have to be additionally tested. Our advice for the end users is to test PHP 7.1 on a development copy of their sites and if everything works as expected then also start using PHP 7.1 on the live sites. In order to easily create a dev copy of a WordPress or Joomla! site you may use our staging tool.

We also carefully tested our WordPress and Joomla! SuperCacher plugins and we are happy to say that they work as expected with PHP 7.1.

How to change the PHP version on your SiteGround account to 7.1

siteground-php-version-manager

Our unique server setup allows users to use different PHP versions for different folders. By default the PHP version for every new account is 5.6. We offer a tool in cPanel called “PHP Version Manager” and it could be used to change the default PHP version for a folder to the new 7.1 release. In order to change the PHP version for your site or for a specific folder just go to cPanel → “PHP Version Manager” and select the folder in which your site resides. Then select PHP 7.1.0 and click the “Save” button as shown in this screenshot:

PHP 7.1 is already available on all shared servers and will be deployed to Cloud servers too in the following days. Dedicated server users can also receive it upon request.

Access email sent!

Sign Up For
More Awesome Content!

Subscribe to receive our monthly newsletters with the latest helpful content and offers from SiteGround.

Thanks!

Please check your email to confirm your subscription.

Daniel Kanchev

Director Product Development

Daniel is responsible for bringing new products to life at SiteGround. This involves handling all types of tasks and communication across multiple teams. Enthusiastic about technology, user experience, security and performance, you can never be bored hanging around him. Also an occasional conference speaker and travel addict.

Comments ( 4 )

author avatar

Paul Coughlin

Dec 02, 2016

You guys are just too good! Thanks for being awesome :-)

Reply
author avatar

Angelo

Dec 05, 2016

spontaneus review: upgrading from php 5.4 to php 7.1 with growbig hosting plan made a big difference for our website, decreasing a lot (around 1.6 seconds) homepage loading time and loading inside pages a lot more quickly than before, thank you Siteground!

Reply
author avatar

Adam

Dec 07, 2016

Did y'all remove the 7.1 option? I'm not seeing it on my shared account: http://d.pr/i/cL90/5y0ej60C

Reply
author avatar

Hristo Pandjarov Siteground Team

Dec 07, 2016

PHP 7.1 is available, it's just the tool on your server that needs to be refreshed and it will be fixed in few moments.

Reply

Start discussion