Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Yield Or Return

<?php

function foo() {
    yield 1;
    yield 2;
    yield 3;
    
    return ['a', 'b', 'c'];
}

function foo2() {
    return ['a', 'b', 'c'];
}

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

goo(...foo());
goo(...foo2());

It is possible to spread an array as dynamic arguments: this applies to returned arrays, after a function call.

The function call may be actually of two types: function or a generator.

The first type is a generator: then, the yielded values are used as argument and the returned array is ignored.

In the second case, the array is returned and used.

See Also

PHP Features

Last updated: 10 September 2026