PHP 5.5 Generator during iteration

Code
<?php

define
('REWIND''doing rewind' PHP_EOL);
define('NEXT''doing next' PHP_EOL);
define('CURRENT''show current: ');
define('VALID''is valid: ');

$func = function() {
    echo 
'+ start' PHP_EOL;
    
$array range(02);
    
    foreach(
$array as $int) {
        echo 
'+ before yield' PHP_EOL;
        yield 
$int;
        echo 
'+ after yield' PHP_EOL;
    }
    echo 
'+ end' PHP_EOL;
};

$generator $func();

// processing like in a loop
echo REWIND;
$generator->rewind();
echo 
VALID;
echo 
'"' $generator->valid() . '"' PHP_EOL;
echo 
CURRENT;
echo 
'"' $generator->current() . '"' PHP_EOL;
echo 
NEXT;
$generator->next();
echo 
VALID;
echo 
'"' $generator->valid() . '"' PHP_EOL;
echo 
CURRENT;
echo 
'"' $generator->current() . '"' PHP_EOL;
echo 
NEXT;
$generator->next();
echo 
VALID;
echo 
'"' $generator->valid() . '"' PHP_EOL;
echo 
CURRENT;
echo 
'"' $generator->current() . '"' PHP_EOL;
echo 
NEXT;
$generator->next();
echo 
VALID;
echo 
'"' $generator->valid() . '"' PHP_EOL;
Result
doing rewind
+ start
+ before yield
is valid: "1"
show current: "0"
doing next
+ after yield
+ before yield
is valid: "1"
show current: "1"
doing next
+ after yield
+ before yield
is valid: "1"
show current: "2"
doing next
+ after yield
+ end
is valid: ""
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6