summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-12-18 11:04:51 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-12-18 11:04:51 +0100
commit1f5f4736d9346dbfadd380d3175e8f22594c2f4b (patch)
tree133cb921ce371c8b2094568f68bd4a6c3c659725 /Zend
parent48d5100738d4a623a20b68c20ce0316c2e12a765 (diff)
parentbfb38c3592b4cb1e9892802e9f00f5be1232dbef (diff)
downloadphp-git-1f5f4736d9346dbfadd380d3175e8f22594c2f4b.tar.gz
Merge branch 'PHP-7.4'
* PHP-7.4: Rethrow generator exception even without active stack frame
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/generators/exception_during_shutdown.phpt30
-rw-r--r--Zend/zend_generators.c7
2 files changed, 34 insertions, 3 deletions
diff --git a/Zend/tests/generators/exception_during_shutdown.phpt b/Zend/tests/generators/exception_during_shutdown.phpt
new file mode 100644
index 0000000000..d9c8bd0175
--- /dev/null
+++ b/Zend/tests/generators/exception_during_shutdown.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Generator exceptions during shutdown should not be swallowed
+--FILE--
+<?php
+
+function gen() {
+ try {
+ echo "before yield\n";
+ yield;
+ echo "after yield\n";
+ } finally {
+ echo "before yield in finally\n";
+ yield;
+ echo "after yield in finally\n";
+ }
+ echo "after finally\n";
+}
+
+$gen = gen();
+$gen->rewind();
+
+?>
+--EXPECTF--
+before yield
+before yield in finally
+
+Fatal error: Uncaught Error: Cannot yield from finally in a force-closed generator in %s:%d
+Stack trace:
+#0 {main}
+ thrown in %s on line %d
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index db286d2c3d..d086892c3a 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -825,9 +825,10 @@ try_again:
if (UNEXPECTED(EG(exception) != NULL)) {
if (generator == orig_generator) {
zend_generator_close(generator, 0);
- if (EG(current_execute_data) &&
- EG(current_execute_data)->func &&
- ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) {
+ if (!EG(current_execute_data)) {
+ zend_throw_exception_internal(NULL);
+ } else if (EG(current_execute_data)->func &&
+ ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) {
zend_rethrow_exception(EG(current_execute_data));
}
} else {