Posted by Arjun on Saturday 4th January 2020

PHP 7.4 - Null coalescing assignment operator

PHP 7.4

The null coalescing assignment operator is a shorthand for null coalescing operations.

Let's take a example code

$data['date'] = $data['date'] ?? new DateTime();

So, instead of writing the previous code, we could write the following:

$data['date'] ??= new DateTime();

If the value of the left-hand parameter is null, then the value of the right-hand parameter is used.