--- /dev/null
-Fatal error: Uncaught exception 'Exception' in %s:%d
+ --TEST--
+ Bug #69740: finally in generator (yield) swallows exception in iteration
+ --FILE--
+ <?php
+
+ function generate() {
+ try {
+ yield 1;
+ yield 2;
+ } finally {
+ echo "finally\n";
+ }
+ }
+
+ foreach (generate() as $i) {
+ echo $i, "\n";
+ throw new Exception();
+ }
+
+ ?>
+ --EXPECTF--
+ 1
+ finally
+
++Fatal error: Uncaught Exception in %s:%d
+ Stack trace:
+ #0 {main}
+ thrown in %s on line %d
/* If a finally block was found we jump directly to it and
* resume the generator. */
if (finally_op_num) {
- ex->opline = &ex->op_array->opcodes[finally_op_num];
- ex->fast_ret = NULL;
- ex->delayed_exception = EG(exception);
+ zval *fast_call = ZEND_CALL_VAR(ex, ex->func->op_array.opcodes[finally_op_end].op1.var);
+
- Z_OBJ_P(fast_call) = NULL;
++ Z_OBJ_P(fast_call) = EG(exception);
+ EG(exception) = NULL;
+ fast_call->u2.lineno = (uint32_t)-1;
+
+ ex->opline = &ex->func->op_array.opcodes[finally_op_num];
generator->flags |= ZEND_GENERATOR_FORCED_CLOSE;
- zend_generator_resume(generator TSRMLS_CC);
+ zend_generator_resume(generator);
}
}
/* }}} */