📜  php 8 大变化 - Nullsafe 运算符 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:50.142000             🧑  作者: Mango

代码示例1
BEFORE
$country =  null;

if ($session !== null) {
  $user = $session->user;

  if ($user !== null) {
    $address = $user->getAddress();
 
    if ($address !== null) {
      $country = $address->country;
    }
  }
}
AFTER
$country = $session?->user?->getAddress()?->country;