Back

/ 1 min read

Null Coalesce Assignment Operator

Use the null coalesce assignment operator (??=) to assign a value to a variable if the variable is null.

// Before (Using the null coalesce operator)
$user->name = $user->name ?? 'guest';
// After (Using the null coalesce assignment operator)
$user->name ??= 'guest';