File tree Expand file tree Collapse file tree 3 files changed +62
-3
lines changed Expand file tree Collapse file tree 3 files changed +62
-3
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ PHP NEWS
26
26
from an array. (Bob)
27
27
. Fixed bug #70987 (static::class within Closure::call() causes segfault).
28
28
(Andrea)
29
+ . Fixed bug #71013 (Incorrect exception handler with yield from). (Bob)
29
30
30
31
- CLI server:
31
32
. Fixed bug #71005 (Segfault in php_cli_server_dispatch_router()). (Adam)
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #71013 (Incorrect exception handler with yield from)
3
+ --FILE--
4
+ <?php
5
+
6
+ class FooBar implements Iterator {
7
+ function __construct () { echo "Constructing new FooBar \n" ; }
8
+ function __destruct () { echo "Destructing FooBar \n" ; }
9
+ function current () { throw new Exception ; }
10
+ function key () { return 0 ; }
11
+ function next () {}
12
+ function rewind () {}
13
+ function valid () { return true ; }
14
+ }
15
+
16
+ function foo () {
17
+ try {
18
+ $ f = new FooBar ;
19
+ yield from $ f ;
20
+ } catch (Exception $ e ) {
21
+ echo "[foo()] Caught Exception \n" ;
22
+ }
23
+ }
24
+
25
+ function bar () {
26
+ echo "Starting bar() \n" ;
27
+ $ x = foo ();
28
+ try {
29
+ var_dump ($ x ->current ());
30
+ } catch (Exception $ e ) {
31
+ echo "[bar()] Caught Exception \n" ;
32
+ }
33
+ echo "Unsetting \$x \n" ;
34
+ unset($ x );
35
+ echo "Finishing bar() \n" ;
36
+ }
37
+
38
+ bar ();
39
+
40
+ ?>
41
+ --EXPECT--
42
+ Starting bar()
43
+ Constructing new FooBar
44
+ [foo()] Caught Exception
45
+ Destructing FooBar
46
+ NULL
47
+ Unsetting $x
48
+ Finishing bar()
49
+
Original file line number Diff line number Diff line change @@ -573,7 +573,7 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
573
573
if (iter -> index ++ > 0 ) {
574
574
iter -> funcs -> move_forward (iter );
575
575
if (UNEXPECTED (EG (exception ) != NULL )) {
576
- goto failure ;
576
+ goto exception ;
577
577
}
578
578
}
579
579
@@ -583,7 +583,9 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
583
583
}
584
584
585
585
value = iter -> funcs -> get_current_data (iter );
586
- if (UNEXPECTED (EG (exception ) != NULL || !value )) {
586
+ if (UNEXPECTED (EG (exception ) != NULL )) {
587
+ goto exception ;
588
+ } else if (UNEXPECTED (!value )) {
587
589
goto failure ;
588
590
}
589
591
@@ -595,14 +597,21 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
595
597
iter -> funcs -> get_current_key (iter , & generator -> key );
596
598
if (UNEXPECTED (EG (exception ) != NULL )) {
597
599
ZVAL_UNDEF (& generator -> key );
598
- goto failure ;
600
+ goto exception ;
599
601
}
600
602
} else {
601
603
ZVAL_LONG (& generator -> key , iter -> index );
602
604
}
603
605
}
604
606
return SUCCESS ;
605
607
608
+ exception : {
609
+ zend_execute_data * ex = EG (current_execute_data );
610
+ EG (current_execute_data ) = generator -> execute_data ;
611
+ zend_throw_exception_internal (NULL );
612
+ EG (current_execute_data ) = ex ;
613
+ }
614
+
606
615
failure :
607
616
zval_ptr_dtor (& generator -> values );
608
617
ZVAL_UNDEF (& generator -> values );
You can’t perform that action at this time.
0 commit comments