Skip to content

Commit b396fb3

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix handling of exception if valid() during yield from
2 parents c45985d + ad750c3 commit b396fb3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Exception from valid() during yield from
3+
--FILE--
4+
<?php
5+
6+
class FooBar implements Iterator {
7+
function rewind() {}
8+
function current() {}
9+
function key() {}
10+
function next() {}
11+
function valid() {
12+
throw new Exception("Exception from valid()");
13+
}
14+
}
15+
16+
function gen() {
17+
try {
18+
yield from new FooBar;
19+
} catch (Exception $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
}
23+
24+
$x = gen();
25+
$x->current();
26+
27+
?>
28+
--EXPECT--
29+
Exception from valid()

Zend/zend_generators.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
728728
}
729729

730730
if (iter->funcs->valid(iter) == FAILURE) {
731+
if (UNEXPECTED(EG(exception) != NULL)) {
732+
goto exception;
733+
}
731734
/* reached end of iteration */
732735
goto failure;
733736
}

0 commit comments

Comments
 (0)