<?php
function foo() {
$string = yield;
echo $string;
for ($i = 1; $i <= 3; $i++) {
yield $i;
}
}
$generator = foo();
$generator->send('Hello world!');
foreach ($generator as $value) echo "$value\n";
?>
This code falls with the error:
PHP Fatal error: Uncaught exception 'Exception' with message 'Cannot rewind a generator that was already run'.
foreach internally calls rewind, you should remember this!