PHP 7 уже здесь!

PHP 7 уже здесь!

For several months we have been offering the pre-release versions of PHP to all our customers, and today we are excited to see that the final PHP 7.0.0 has been released! So, what's new:

Up to 2X faster!

PHP 7 is based on the PHPNG (Next-Gen) project and will make your web sites run much faster. People are reporting speed gains from 25% to 70% in real-world situations.

More function argument type hints

When defining a function, you can now declare which parameter types the function will accept. Previously, you could declare certain class names or the special array keyword, but now you can also use bool, float, int, and string. About time! Furthermore, it is now possible to declare what the function will return. You can use the same types as when declaring the parameters. So this function will automatically return a float when invoked from other parts of the application:

<?php
function sum($a, $b): float {
    return $a + $b;
}
?>

The spaceship operator

A handy operator that Perl users may be familiar with can now be used in PHP: <=>. It looks a bit like a spaceship and is used to compare values, like the strcmp() function does.

The null coalesce operator

This shorthand operator, ??, is a short way of checking whether a value is set, or defaulting to another value. In the following example, $username will be set to $_GET['username'] if that variable is set, or nobody otherwise.

<?php
$username = $_GET['username'] ?? 'nobody';
?>

It is shorter than using isset().

There are several other new features in PHP 7, as well as a lot of clean-up of inconsistencies. Check the complete list of new features on php.net.

PHP 7.0.0 is available today for all Gigahost users. Log on to the Control Center to enable it; you can do it on a per-domain basis!