[php-src] Issue #8289: Exceptions thrown within a yielded from iterator are not rethrown into the generator
| From: | bwoebi | Date: | Fri, 01 Apr 2022 14:21:15 +0000 |
| Subject: | [php-src] Issue #8289: Exceptions thrown within a yielded from iterator are not rethrown into the generator | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240636@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8289
Author: bwoebi
### Description
The following code (https://3v4l.org/pvIjH):
```php
<?php
function yieldFromIteratorGeneratorThrows() {
try {
yield from new class(new ArrayIterator([1, -2])) extends IteratorIterator {
public function key() {
if ($k = parent::key()) {
throw new Exception;
}
return $k;
}
};
} catch (Exception $e) {
yield 2;
}
}
foreach (yieldFromIteratorGeneratorThrows() as $k => $v) {
var_dump($v);
}
```
Resulted in this output:
```
int(1)
```
But I expected this output instead:
```
int(1)
int(2)
```
(I'm looking at fixing the issue)
### PHP Version
PHP 7.2 - master
### Operating System
_No response_