Ellipsis And Coalesce¶
<?php
$a = [3];
foo(...$a ?? range(1,2));
$a = [null];
foo(...$a ?? range(1,2));
$a = null;
foo(...$a ?? range(1,2));
function foo() {
print_r(func_get_args());
}
Ellipsis, aka ... three dots, applies only to arrays and Traversable objects. It also has a lower priority than the ?? coalesce operator, which means that ?? is applied before the ....
This way, when the variable is undefined, it is still possible to unpack it, after having given a default value.
See Also¶
PHP Features¶
Last updated: 14 July 2026