DEV Community

Morcos Gad
Morcos Gad

Posted on

5 Reasons to Use PHP 8

Let's start quickly
Match :-
Image description

Null safe operator :-
Image description

- $address = $customer->getAddress();
- $country = $address ? $address->getCountry() : null;
+ $country = $customer->getAddress()?->getCountry();

Named parameters :-
Image description

Constructor property promotion :-
Image description

Union types :-

Given the dynamically typed nature of PHP, there are lots of cases where union types can be useful. Union types are a collection of two or more types which indicate that either one of those can be used.

public function foo(Foo|Bar $input): int|float;

Source :-

I hope everyone enjoys.

Top comments (0)