api call php 8.0 code example
Example 1: php8
// php 8 Union type
class Number {
public function __construct(
private int|float $number
) {}
}
new Number('NaN'); // TypeError
Example 2: php8
// php8 is null or not
$country = $session?->user?->getAddress()?->country;
//-----------------------------
// php7 below.
$country = null;
if ($session !== null) {
$user = $session->user;
if ($user !== null) {
$address = $user->getAddress();
if ($address !== null) {
$country = $address->country;
}
}
}