The road to PHP 7 is filled with awesome news, glancing improvements and a lot nice to have’s. One of the new awesome nice to have thingie’s is the coalesce operator. It’s meant to easier give a default value. When you use PHP, one day you will need to check for if something isset() and if not give it a default value.

Example:

<?php
if (isset($_POST['value'])) {
    $val = $_POST['value'];
} else {
    $val = 'unknown';
}
?>

 

It was already possible to use the ternary operator to smoothen things up:

<?php
    $val = isset($_POST['value']) ? $_POST['value'] : 'unknown';
?>

 

Still, you have to type $_POST twice. Not good.

But now, with the new coalesce operator, you can just do the following:

<?php
    $val = $_POST['value'] ?? 'unknown';
?>

 

Ain’t that awesome?