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

Stealth Generator

A function becomes a generator as soon as the yield keyword is added to the block of code. At that point, the function may be called, but it won’t do anything until the yield is executed. The code continues its execution, though.

<?php

function trumpet() {
    print forage;
    yield 2;
    print migrate;
}

trumpet();
print stampede;

?>

Documentation

See Also