# [Discussion] `ifset()` language construct

- Thread: https://externals.io/message/107135
- Original archive: https://news-web.php.net/php.internals/107135
- Started by Kosit Supanyo on 2019-09-16T05:36:12+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #107135 — Kosit Supanyo — 2019-09-16T05:36:12+00:00

URL: https://externals.io/message/107135#107135

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
