upgrades

At the start of 2016 we have began updating our client web servers  to use PHP version 7, as we wanted to take advantage of the immediate performance benefits it brings.  We first concentrated on the low hanging fruit and updated the Symfony 2 – 3 applications that we develop and manage.  We are yet to look into updating the many  Wordpress servers we maintain as these code bases can often depend upon 3rd party plugins which may not have been tested under php 7.

Using a Ubuntu server it is quite easy to update to PHP 7 simply by adding the PPA.  Once PHP 7 is installed we can expect quicker response times (which we have witnessed) as well as access to the new features of PHP 7.

New Features of PHP 7

If you wish to read about all the new features in PHP 7 then you can do so here.  However we will discuss a couple that we have enjoyed using so far below:

Return type declarations and Scalar type declarations

This is a couple of new features we started using right away.  When developing you domain code, we practice true professionalism by practicing TDD (test driven development) and as such we also try to follow the SOLID principals.  Writing code in this way has many benefits, and it is now aided by the addition of return type and scalar argument type declarations:

public function getUniversityId() : int
{
    return $this->universityId;
}

public function setUniversityId(int $universityId)
{
    $this->universityId = $universityId;
}

Using these new features allows us in the PHP community to structure our code in a more strict way, and provides clarity when reading code.  It also allows IDEs to better predict what is expected from a method of some object.  A breath of fresh air in a language which has a bad reputation for ugly code.

Anonymous Classes

We have not used these much yet, but I can already think of many situations recently when these would be useful.  Specifying interfaces and being able to create anonymous classes that are very simple and implement those interfaces is extremely convenient.

So far PHP 7 has been a great improvement for us and we hope this continues and improves the code bases of our existing frameworks and CMSs such as Symfony, WordPress, Magento, Drupal and Zend.