Functional Null Coalesce for PHP

A simple-looking construct is needed for the use of sometimes-declared variables. After considering alternatives, I propose adding a function-like language construct for the purpose of coalescing undeclared variables.

The common challenge: Need to test the value of a variable whose existence is unknown.

Existing solutions:

$input = $_POST['input'] ?? 'none';
if ($input === 'yes') echo 'success';

$_POST['input'] ??= 'none';
if ($_POST['input'] === 'yes') echo 'success';

Needed solution: What we don’t have is a Variable Handling Function that will concisely resolve any uninitialized variable.

// Hypothetical
if (nullc($_POST['input']) === 'yes') echo 'success';
Continue reading Functional Null Coalesce for PHP