Match expression
Unlike the “switch” expression in php, the match expression doesn’t require the break statement. It works exactly like a switch expresion. It uses strict comaprisons and doesn’t support type coersion.
Example:
$result = match($input) {
0 => "hello",
'1', '2', '3' => "world",
};
New “static” return type
Now, static can be used as a return type! This feature will be very useful to the developers due to PHP’s dynamically typed nature.
Example:
class Foo
{
public function test(): static
{
return new static();
}
}
New mixed type
The mixed type can be used when we are experiencing one of the following things:
“mixed” type can mean any one of the following things:
Note:mixed type can also be used as a parameter or property type. Also note that since mixed already includes null, it's not allowed to make it nullable.
Throw expression
“throw” is no more a statement, but an expression now, which enables us to throw exceptions in many new places.
Example:
$triggerError = fn () => throw new MyError();
$foo = $bar['offset'] ?? throw new OffsetDoesNotExist('offset');
We are known for Website Development and Website Designing, along with Android iOS application development in Mumbai, India.