Generator::getReturn

(PHP 7)
Get the return value of a generator
public mixed Generator::getReturn ( void )
Returns:

Returns the generator's return value once it has finished executing.

Examples:
Generator::getReturn() example
<?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:

1
2
3
doc_php
2016-02-24 15:53:35
Comments
Leave a Comment

Please login to continue.