Hi Internals
I don't have permission to create RFCs but I would like to propose/discuss
new language construct called `ifset()` which is syntactic sugar to null
coalescing operator with rhs value `null`. The goal of this proposal is
similar to Andrea Fauld's proposal (
https://wiki.php.net/rfc/unary_null_coalescing_operator), and the chosen
keyword is similar to historical discussion `ifsetor()`. Here's an example.
$result = $a ?? null;
vs
$result = ifset($a);
$result = $a ?? $b ?? $c ?? $d ?? $e ?? null;
vs
$result = ifset($a, $b, $c, $d, $e);
As you can see `ifset()` does not make code much shorter but the main goal
of this syntax is expressiveness not shortness.
someFunc(
$arg1,
$arg2,
$longVariableName1 ?? $longVariableName2 ?? $longVariableName3 ?? null,
$arg4,
);
vs
someFunc(
$arg1,
$arg2,
ifset(
$longVariableName1,
$longVariableName2,
$longVariableName3,
),
$arg4,
);
I know that this proposal is highly unlikely to be accepted because it just
does same as `??` but in different way and it introduces new keyword (we
don't have any new keyword since `yield` in 5.5) and, furthermore, I did
search through github and found some projects using `ifset` as function
name (https://github.com/search?l=PHP&q=ifset&type=Code).
Here's the patch: https://github.com/webdevxp/php-src
Cheers