PHP 7 is here!
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-word 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's 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 maybe 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 shorthand way of checking if a value is set, or default 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's shorter than using isset()
.
There's 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 the Control Center to enable it (you can do it on a per-domain basis!)