File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-20714: Uncatchable exception thrown in generator
3+ --CREDITS--
4+ Grégoire Paris (greg0ire)
5+ --FILE--
6+ <?php
7+
8+ function gen (): Generator {
9+ try {
10+ yield 1 ;
11+ } finally {}
12+ }
13+
14+ function process (): void {
15+ $ g = gen ();
16+ foreach ($ g as $ _ ) {
17+ throw new Exception ('ERROR ' );
18+ }
19+ }
20+
21+ try {
22+ process ();
23+ } catch (Exception $ e ) {
24+ echo "Caught \n" ;
25+ }
26+
27+ ?>
28+ --EXPECT--
29+ Caught
Original file line number Diff line number Diff line change @@ -312,7 +312,9 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
312312 zend_object * old_exception = NULL ;
313313 const zend_op * old_opline_before_exception = NULL ;
314314 if (EG (exception )) {
315- if (EG (current_execute_data )) {
315+ if (EG (current_execute_data )
316+ && EG (current_execute_data )-> opline
317+ && EG (current_execute_data )-> opline -> opcode == ZEND_HANDLE_EXCEPTION ) {
316318 EG (current_execute_data )-> opline = EG (opline_before_exception );
317319 old_opline_before_exception = EG (opline_before_exception );
318320 }
@@ -329,7 +331,7 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
329331 zend_generator_resume (generator );
330332
331333 if (old_exception ) {
332- if (EG ( current_execute_data ) ) {
334+ if (old_opline_before_exception ) {
333335 EG (current_execute_data )-> opline = EG (exception_op );
334336 EG (opline_before_exception ) = old_opline_before_exception ;
335337 }
You can’t perform that action at this time.
0 commit comments