diff options
-rw-r--r-- | Zend/tests/generators/yield_from_valid_exception.phpt | 29 | ||||
-rw-r--r-- | Zend/zend_generators.c | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Zend/tests/generators/yield_from_valid_exception.phpt b/Zend/tests/generators/yield_from_valid_exception.phpt new file mode 100644 index 0000000000..3af35f53af --- /dev/null +++ b/Zend/tests/generators/yield_from_valid_exception.phpt @@ -0,0 +1,29 @@ +--TEST-- +Exception from valid() during yield from +--FILE-- +<?php + +class FooBar implements Iterator { + function rewind() {} + function current() {} + function key() {} + function next() {} + function valid() { + throw new Exception("Exception from valid()"); + } +} + +function gen() { + try { + yield from new FooBar; + } catch (Exception $e) { + echo $e->getMessage(), "\n"; + } +} + +$x = gen(); +$x->current(); + +?> +--EXPECT-- +Exception from valid() diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 4ccb57907f..bb3260b11b 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -709,6 +709,9 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /* } if (iter->funcs->valid(iter) == FAILURE) { + if (UNEXPECTED(EG(exception) != NULL)) { + goto exception; + } /* reached end of iteration */ goto failure; } |