Coalesce And Null¶
<?php
// very slow
$total = @$x;
// looks weird
$total = $x ?? null;
// lengthy
if (!isset($x)) {
$total = null;
} else {
$total = $x;
}
?>
I’m still struggling to pick a side in this debate.
@ is too slow, because it merely hides the error.
?? looks dumb. It looks like : if it is null, use null as default.
The if() command is long to type.
Is there another way to handle this issue?
See Also¶
PHP Features¶
Last updated: 14 July 2026