While the world was busy ushering the new year with parties and celebrations, the Gregorian calendar wasn't the only thing experiencing a transition. December 31, 2016 marked the end of active support for PHP 5.6, the final release of the PHP 5 branch. PHP 5.6 will continue to receive support for critical security issues only for the next two years, but now is as good a time as any to make the leap to PHP 7.

Due to the end of active support for PHP 5.6, Plank is announcing that all new projects will be written in PHP 7.0 or above. This means that our contracts have been updated to require our clients provide hosting with PHP 7.0 or PHP 7.1. As always, we are happy to consult with our clients to help them find hosting tailored to their needs or even perform the server set up ourselves.

We will continue to support existing maintenance projects on older versions of PHP, though we will be encouraging site owners to consider upgrading whenever significant changes are planned.

What's the Rush?

While it is true that with a full two years of security support still ahead of it, PHP 5.6 is far from unusable at this point, moving to PHP 7 comes with a large number of benefits.

  • Efficiency: First and foremost, PHP 7.0 is leaps and bounds faster than its predecessors, pages load faster and the server can handle more requests in parallel. Zend's benchmarks showed that PHP 7.0 roughly doubles the requests that can be handled per second by most of the major frameworks and content management systems. PHP 7.0 even edges out HHVM.
  • Scalar Type Hints: One of the most requested and also most controversial new features of PHP 7.0 is the ability to enforce the method argument type for scalar data types (boolean, integer, float, and string). This helps to ensure that code is always operating on expected values. It also serves a secondary benefit of making code more self-documenting, as the method signature can inform the type of input expected.
    public function setScore(string $player, int $score){ ... }
  • Return Types: Similar to scalar type hints, it is now possible to declare the data type of the return value of a function or method. The PHP engine will throw an exception if the return value is not of the expected type, helping to catch unintended bugs. Again, this also makes code more self-documenting.
    public function getScore(string $player) : int { ... }
  • Null Coalescing Operator: A common task in PHP development is checking if a variable is set before it can be worked with. The process for this can be somewhat verbose:
    $name = isset($_GET['name']) ? $_GET['name'] : 'John Doe';
    With PHP 7.0, a new operator makes this process much cleaner. The "null coalescing operator" checks if a variable and return it if it exists and is not null, otherwise returns a fallback.
    $name = $_GET['name'] ?? 'John Doe';

These are only the features that most excited us, but these are just the tip of the iceberg. Find out about these features and a number of others on the official PHP 7.0 migration page.

What about PHP 7.1?

PHP 7.0 has been out for over a year now, so hopefully most of the above is already common knowledge. In fact, PHP 7.0 isn't even the newest version. In early December, PHP 7.1 was released, bringing with it a number of other exciting changes.

  • Nullable Type hints and Void Return Type: The method argument and return type hints added in PHP 7.0 become more robust, making it easy to specify that an argument or return value can be of a specified type or null. The void return type has also been added to specify functions which should not return anything.
  • Class Constant Visibility: class constants can now be restricted to protected or private visibility, to keep information important to the internal workings of a class from being exposed.
  • Iterable Pseudo-Type: A long time headache in PHP has been the fact it is possible to typehint for arrays or objects implementing Traversable (such as iterators and collections), but not both. The iterable pseudo-type will now allow you to ensure that your input will work with a foreach loop.

For the full list of features introduced in 7.1, see the PHP 7.1 migration page.

Plank is not requiring 7.1 in our contracts yet, but we always encourage our clients to use the most up-to-date software available. Whatever version you use, we look forward to crafting great websites with you using the best tools available!

Technology Development