Glossary

Nullsafe Operator (?->)

The nullsafe operator (?->) is PHP 8.0 syntax that automatically short-circuits a method chain and returns null if any intermediate result is null. It eliminates nested null checks.

Before and after

// Before PHP 8.0 — verbose
$city = null;
if ($user !== null) {
  if ($user->getAddress() !== null) {
    $city = $user->getAddress()->getCity();
  }
}

// PHP 8.0+ — one line
$city = $user?->getAddress()?->getCity();

Rules