New Features in PHP 7

https://blog.feryn.eu/php-7-is-now-available-new-features-improvements/

1) Speed

2) Type Declarations:
Since PHP 5, you can use type hinting to specify the expected data type of an argument in a function declaration, but only in the declaration. When you call the function, PHP will check whether or not the arguments are of the specified type. With PHP 7 we now have added Scalar types. Specifically: int, float, string, and bool.

function stringTest(string $string) {
    echo $string;
 }

Additionally, PHP 7 gives us the opportunity to enable strict mode on a file by file basis. We do this by declare(strict_types=1); at the top of any given file.

PHP 7 also supports Return Type Declarations which support all the same types as arguments. To specify the return type, we add a colon and then the type right before the opening curly bracket.

function getTotal(float $a, float $b) : float {

3) Error Handling :
In PHP 7, an exception will be thrown when a fatal and recoverable error occurs, rather than just stopping the script. Fatal errors still exist for certain conditions, such as running out of memory, and still behave as before by immediately stopping the script. An uncaught exception will also continue to be a fatal error in PHP 7. This means if an exception thrown from an error that was fatal in PHP 5 goes uncaught, it will still be a fatal error in PHP 7.

4) New Operators (Spaceship Operator, Null Coalesce Operator) :

Spaceship Operator (useful in sort algorithms, etc)

$compare = 2 <=> 1
2 < 1? return -1
2 = 1? return 0
2 > 1? return 1

the Null Coalesce Operator, is effectively the fabled if-set-or.
If $firstName is empty then set it to Guest.

$name = $firstName ??  "Guest";

Can be chained.

$name = $firstName ?? $username ?? $placeholder ?? “Guest”; 


5) Anonymous Classes :

Anonymous classes are useful when simple, one-off objects need to be created.

$util->setLogger(new class {
    public function log($msg)
    {
        echo $msg;
    }
});

http://blog.teamtreehouse.com/5-new-features-php-7