Predefine value type of method or function: (Scalar Type Hints)

Note: need to add declare(strict_types = 1) very  top to generate Fatal error: Uncaught TypeError: Argument 1 passed to double() must be of the type integer, string given.

Predefine function or method  return value by adding “:  type” beside function name  .

Note: need to add declare(strict_types = 1) very  top to generate Fatal error: Uncaught TypeError: Return value of a() must be of the type boolean, integer returned.


New and Quick Operator to check if the value is set:

Php 5 uses:

Note: ??” is used for check null

The spaceship operator “<=>"is a new operator to hand multiple conditioning tasks at once.

This expression will evaluate to -1 if $a is smaller than $b0 if $a equals $b, and 1 if $a is greater than $b. It’s basically a shortcut for the following expression:

Uniform Variable Syntax
Solve inconsistencies of evaluating variable -variable . Example:


In PHP 5, the expression $person->$property['first'] is evaluated as $person->{$property['first']}. In practical terms, this will be interpreted as $person->name, giving you the result “My name is Erika”. Even though this is an edge case, it shows clear inconsistencies with the normal expression evaluation order, which is left to right.

In PHP 7, the expression $person->$property['first'] is evaluated as {$person->$property}['first']. The interpreter will evaluate $person->$property first; consequently, the previous code example won’t work in PHP 7 because $property is an array and cannot be converted to a string.

A quick and easy way to fix this problem is by explicitly defining the evaluation order with the help of curly braces (e.g. $person->{$property['first']}), which will guarantee the same behavior on both PHP 5 and PHP 7.

Thanks to the new uniform left-to-right variable syntax, many expressions previously treated as invalid will now become valid. To illustrate this new behavior, consider the following class:

With PHP 7, we can create nested associations and different combinations between operators:

This snippet would give us a parse error on PHP 5, but works as expected on PHP 7.

Similarly, nested static access is also possible:

Inspired by: