mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.5'
* PHP-8.5: Fix uncatchable exception thrown in generator
This commit is contained in:
29
Zend/tests/gh20714.phpt
Normal file
29
Zend/tests/gh20714.phpt
Normal file
@@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
GH-20714: Uncatchable exception thrown in generator
|
||||
--CREDITS--
|
||||
Grégoire Paris (greg0ire)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function gen(): Generator {
|
||||
try {
|
||||
yield 1;
|
||||
} finally {}
|
||||
}
|
||||
|
||||
function process(): void {
|
||||
$g = gen();
|
||||
foreach ($g as $_) {
|
||||
throw new Exception('ERROR');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
process();
|
||||
} catch (Exception $e) {
|
||||
echo "Caught\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Caught
|
||||
@@ -312,7 +312,9 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
|
||||
zend_object *old_exception = NULL;
|
||||
const zend_op *old_opline_before_exception = NULL;
|
||||
if (EG(exception)) {
|
||||
if (EG(current_execute_data)) {
|
||||
if (EG(current_execute_data)
|
||||
&& EG(current_execute_data)->opline
|
||||
&& EG(current_execute_data)->opline->opcode == ZEND_HANDLE_EXCEPTION) {
|
||||
EG(current_execute_data)->opline = EG(opline_before_exception);
|
||||
old_opline_before_exception = EG(opline_before_exception);
|
||||
}
|
||||
@@ -329,7 +331,7 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
|
||||
zend_generator_resume(generator);
|
||||
|
||||
if (old_exception) {
|
||||
if (EG(current_execute_data)) {
|
||||
if (old_opline_before_exception) {
|
||||
EG(current_execute_data)->opline = EG(exception_op);
|
||||
EG(opline_before_exception) = old_opline_before_exception;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user