<?php
function bar($x) {
yield from $x;
}
/* Twice a Generator from bar() using yield from on $gen */
$it = [1, 2, 3, 4];
$gens[] = bar($it);
$gens[] = bar($it);
$i = 0;
do {
foreach ($gens as $g) {
var_dump($g->current());
$g->next();
}
$i++;
} while($gens[0]->valid());
var_dump($gens[1]->valid());
- Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- int(1)
int(1)
int(2)
int(2)
int(3)
int(3)
int(4)
int(4)
bool(false)
- Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
- Parse error: syntax error, unexpected '$x' (T_VARIABLE) in /in/7g6Bm on line 4
Process exited with code 255.
preferences:
142.49 ms | 402 KiB | 199 Q