Field Manual PHP / Laravel reference
← PHP

Null handling

?? supplies a default for absent/null values; ?-> stops a chain on null.

What it is

?? supplies a default for absent/null values; ?-> stops a chain on null.

When to use it

Handle optional values without repeated null checks.

Syntax

$name = $input["name"] ?? "Guest";
$city = $user?->address?->city;

Example

$email = $payload["email"] ?? null;
$city = $customer?->address?->city ?? "Unknown";

Common mistakes

?? does not replace false or empty strings; ?-> is for objects and cannot be assigned through.

Related topics

Secure error handlingError handlingFailure handling