xref: /php-src/Zend/tests/generators/gh8289.phpt (revision e4c7ffc1)
1--TEST--
2GH-8289 (Exceptions thrown within a yielded from iterator are not rethrown into the generator)
3--FILE--
4<?php
5
6function yieldFromIteratorGeneratorThrows() {
7	try {
8		yield from new class(new ArrayIterator([1, -2])) extends IteratorIterator {
9			public function key(): mixed {
10				if ($k = parent::key()) {
11					throw new Exception;
12				}
13				return $k;
14			}
15		};
16	} catch (Exception $e) {
17		echo "$e\n";
18		yield 2;
19	}
20}
21
22foreach (yieldFromIteratorGeneratorThrows() as $k => $v) {
23    var_dump($v);
24}
25
26?>
27--EXPECTF--
28int(1)
29Exception in %s:%d
30Stack trace:
31#0 %s(%d): IteratorIterator@anonymous->key()
32#1 %s(%d): yieldFromIteratorGeneratorThrows()
33#2 {main}
34int(2)
35