# Null Coalesce Handling Revised

- Thread: https://externals.io/message/133205
- Original archive: https://news-web.php.net/php.internals/133205
- Started by Robert Chapin on 2026-11-23T16:54:09+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #133205 — Robert Chapin — 2026-11-23T16:54:09+00:00

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

I wrote last year about an idea to make it easier to handle variables 
that are either unset or uninitialized.

https://news-web.php.net/php.internals/126826

That idea fizzled because a Variable Handling Function didn't seem like 
the best approach, was tricky to name, and had concerns about how to set 
default values.

I've refined this a bit to contemplate userland functions where we might 
want or need to coalesce a variable of unknown status. The new idea is 
to allow a `??` prefix for parameter type hints.

A hypothetical signature...

function array_coalesce(??array $input = null): array;

... could accomplish a few things:

It allows the user's function to define a parameter that is both 
optional and allows an unset variable to be "passed" without errors.

Type safety can still prevent incorrect variable types.

A default value is supplied, which allows this feature to be used in 
more situations.

This won't introduce any new names or abbreviations, instead reusing the 
?? operator token.

Order of operation problems are solved by calling this hypothetical 
function instead of using the ?? operator.   In other words, if $b is 
unset and someone attempts `if ($a === $b ?? [])` we have a missing set 
of parentheses and a runtime warning. However, `if ($a === 
array_coalesce($b))` becomes an intuitive and viable approach to testing 
the value of $b.

Foreseeable questions:

Would these parameters be implicitly nullable?

Is there a significant need for this feature?

-------------
Robert Chapin
