$country = null;
if ($session !== null) {
$user = $session->user;
if ($user !== null) {
$address = $user->getAddress();
if ($address !== null) {
$country = $address->country;
}
}
}
/*Instead of null check conditions, you can now use a chain of calls with the
new nullsafe operator. When the evaluation of one element in the chain fails,
the execution of the entire chain aborts and the entire chain evaluates to null. */
// Example
$country = $session?->user?->getAddress()?->country;