xref: /PHP-7.2/Zend/tests/generators/bug74954.phpt (revision bad5d0d6)
1--TEST--
2Bug #74954 (crash after update of generator yielding from finished generator)
3--FILE--
4<?php
5
6function from() {
7        yield 1;
8        throw new Exception();
9}
10
11function gen($gen) {
12        try {
13                var_dump(yield from $gen);
14        } catch (Exception $e) { print "Caught exception!\n$e\n"; }
15}
16
17$gen = from();
18$gens[] = gen($gen);
19$gens[] = gen($gen);
20
21foreach ($gens as $g) {
22        $g->current();
23}
24
25do {
26        foreach ($gens as $i => $g) {
27                $g->next();
28        }
29} while($gens[0]->valid());
30
31?>
32--EXPECTF--
33Caught exception!
34Exception in %s:%d
35Stack trace:
36#0 %s(%d): from()
37#1 [internal function]: gen(Object(Generator))
38#2 %s(%d): Generator->next()
39#3 {main}
40Caught exception!
41ClosedGeneratorException: Generator yielded from aborted, no return value available in %s:%d
42Stack trace:
43#0 [internal function]: gen(Object(Generator))
44#1 %s(%d): Generator->next()
45#2 {main}
46