Generator::getReturn
PHP function
Edit on GitHub ✎
(PHP 7, PHP 8)
Get the return value of a generator
Description
Generator::getReturn(): mixed
Parameters Parameters
Return Values
Returns the generator's return value once it has finished executing.
Examples
Generator::getReturn example
php
<?php
$gen = (function() {
yield 1;
yield 2;
return 3;
})();
foreach ($gen as $val) {
echo $val, PHP_EOL;
}
echo $gen->getReturn(), PHP_EOL;The above example will output:
output
1
2
3