facebook / facebook/hhvm

foreach over a generator with an intermit send() fails with a fatal error

Open
#8,152 0 comments 0 reactions 0 assignees View on GitHub
php5 incompatibility php7 incompatibility
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

### HHVM Version
hhvm-3.18.5 - 3.21.3, hhvm-3.22.0
### Operating System and Version
What 3v4l.org uses, probably Linux
### Standalone code, or other way to reproduce the problem
```php
/** @return Generator */
function example() {
for ($i = 0; $i < 5; $i += 1) {
$answer = (yield $i * 2);
echo "received: $answer\n";
}
}

$gen = example();
foreach ($gen as $x) {
echo "sending $x\n";
$gen->send($x);
}
```
[Demo here](https://3v4l.org/bfg64#vhhvm-3220)
### Expected result
No error.
### Actual result
Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished'

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.