Null coalescing operator
The Null
coalescing operator (??
) is a syntactical sugar, but a important one. Previously in PHP5 when we were having some variable which could be undefined, we used the ternary
operator as follows:
$username = isset($_GET['username']) ? $_GET['username'] : '';
However, now in PHP7, we can simply write:
$username = $_GET['username'] ?? '';
Although this is just a syntactical sugar, it can save time and make code cleaner.