Skip to content

Commit df2db7f

Browse files
committed
Fixed bug #79657
Throwing an exception should count as an initialization for this purpose.
1 parent 9b39ddb commit df2db7f

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
. Fixed bug #79650 (php-win.exe 100% cpu lockup). (cmb)
88
. Fixed bug #79668 (get_defined_functions(true) may miss functions). (cmb,
99
Nikita)
10+
. Fixed bug #79657 ("yield from" hangs when invalid value encountered).
11+
(Nikita)
1012

1113
- Filter:
1214
. Fixed bug #73527 (Invalid memory access in php_filter_strip). (cmb)

Zend/tests/bug79657.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Bug #79657: "yield from" hangs when invalid value encountered
3+
--FILE--
4+
<?php
5+
6+
function throwException(): iterable
7+
{
8+
throw new Exception();
9+
}
10+
11+
function loop(): iterable
12+
{
13+
$callbacks = [
14+
function () {
15+
yield 'first';
16+
},
17+
function () {
18+
yield from throwException();
19+
}
20+
];
21+
22+
foreach ($callbacks as $callback) {
23+
yield from $callback();
24+
}
25+
}
26+
27+
function get(string $first, int $second): array
28+
{
29+
return [];
30+
}
31+
32+
get(...loop());
33+
34+
?>
35+
--EXPECTF--
36+
Fatal error: Uncaught Exception in %s:%d
37+
Stack trace:
38+
#0 %s(%d): throwException()
39+
#1 %s(%d): {closure}()
40+
#2 %s(%d): loop()
41+
#3 {main}
42+
thrown in %s on line %d

Zend/zend_generators.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
857857
} else {
858858
generator = zend_generator_get_current(orig_generator);
859859
zend_generator_throw_exception(generator, NULL);
860+
orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT;
860861
goto try_again;
861862
}
862863
}

0 commit comments

Comments
 (0)