In PHP 7 this was originally released, allowing a developer to simplify an isset() check combined with a ternary operator. For example, before PHP 7, we might have this code:
$data['username'] = (isset($data['username']) ? $data['username'] : 'guest');
When PHP 7 was released, we got the ability to instead write this as:
$data['username'] = $data['username'] ?? 'guest';
Now, however, when PHP 7.4 gets released, this can be simplified even further into:
$data['username'] ??= 'guest';
One case where this doesn't work is if you're looking to assign a value to a different variable, so you'd be unable to use this new option. As such, while this is welcomed there might be a few limited use cases.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…