Davechild - php8 What S New in php8
Davechild - php8 What S New in php8
Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/27364/
void Function will not return public function foo(Foo|Bar Match expression
anything $input): int|float;
$result = match($input) {
static Function may return You can now specify more than one type in 0 => "hello",
static a type hint: '1', '2', '3' => "wor‐
• The void type cannot be part of a union.
ld",
New mixed type • Unions can be nullable by including null
};
Mixed means any one of: as a type or preceding with a question
Switch statements made simple. Note, the
array bool callable mark.
comparisons made by match use strict
string int resource types.
Named arguments
float null object
function foo(string $a, int $b,
Note that because mixed already contains Constructor property promotion
?string $c = null)
null, it is not nullable itself. class Money
{
{
...
public function __cons‐
}
truct(
foo(
public Currency
c: 'value c',
$currency,
a: 'value a'
public int
);
$amount,
Pass values to functions and methods by
) {}
name, regardless of the order in which they
}
are defined.
In the above example Currency and int
are both automatically made public
properties of the class and assigned values
on construction.
With Thanks