File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Test destructor throwing with unfinished fiber
3+ --FILE--
4+ <?php
5+
6+ new class () {
7+ function __destruct () {
8+ $ fiber = new Fiber (static function () {
9+ Fiber::suspend ();
10+ });
11+ $ fiber ->start ();
12+ throw new Exception ;
13+ }
14+ };
15+
16+ --EXPECTF --
17+ Fatal error: Uncaught Exception in %sthrow-from-destruct-with-fiber.php:%d
18+ Stack trace:
19+ #0 %sthrow-from-destruct-with-fiber.php(%d): class@anonymous->__destruct()
20+ #1 {main}
21+ thrown in %sthrow-from-destruct-with-fiber.php on line %d
Original file line number Diff line number Diff line change @@ -416,8 +416,11 @@ static void zend_fiber_object_destroy(zend_object *object) /* {{{ */
416416 zval_ptr_dtor (& fiber -> fci .function_name );
417417 } else {
418418 if (fiber -> status == ZEND_FIBER_STATUS_SUSPENDED ) {
419+ zend_object * exception = EG (exception );
420+ EG (exception ) = NULL ;
419421 fiber -> status = ZEND_FIBER_STATUS_SHUTDOWN ;
420422 zend_fiber_switch_to (fiber );
423+ EG (exception ) = exception ;
421424 }
422425
423426 zval_ptr_dtor (& fiber -> value );
@@ -434,6 +437,8 @@ static void zend_fiber_object_destroy(zend_object *object) /* {{{ */
434437void zend_fiber_cleanup (void ) /* {{{ */
435438{
436439 zend_fiber * fiber ;
440+ zend_object * exception = EG (exception );
441+ EG (exception ) = NULL ;
437442
438443 ZEND_HASH_REVERSE_FOREACH_PTR (& EG (fibers ), fiber ) {
439444 if (fiber -> status == ZEND_FIBER_STATUS_SUSPENDED ) {
@@ -442,6 +447,8 @@ void zend_fiber_cleanup(void) /* {{{ */
442447 zend_fiber_switch_to (fiber );
443448 }
444449 } ZEND_HASH_FOREACH_END ();
450+
451+ EG (exception ) = exception ;
445452}
446453/* }}} */
447454
You can’t perform that action at this time.
0 commit comments