Variadic All The Yields

<?php

function foo() {
    yield 1;
    yield 2;
    yield 3;

}

function goo($x, $y, $z) {
    print "$x $y $z
";
}

goo(...foo());
// 1 2 3

?>

The ellipsis operator works on generators: it is akin to a foreach() on all the values, or a call to iterator_to_array().

Here, the generator produces three values, and they are used to fill the three argument positions. It makes a kind of shortcut.

See Also

PHP Features

Last updated: 14 July 2026