Skip to content

PHP 7.4 – Null coalescing assignment operator

Last updated on January 30, 2021

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments