[php-src] Issue #8723: Cannot switch fibers in destructor.
| From: | bartvanhoutte | Date: | Tue, 07 Jun 2022 09:06:58 +0000 |
| Subject: | [php-src] Issue #8723: Cannot switch fibers in destructor. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241681@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8723
Author: bartvanhoutte
### Description
👋 I've noticed some unexpected behaviour with Fibers while working with ReactPHP that seem
to boil down to not being able to switch Fibers in a destructor.
```php
<?php
$foo = new class {
public function __destruct()
{
$fiber = new Fiber(function () {
Fiber::suspend(42);
});
var_dump($fiber->start());
}
};
unset($foo);
```
Resulted in this output:
```
/usr/bin/php /home/bart/uv/destructor.php
PHP Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in
/home/bart/uv/destructor.php:11
Stack trace:
#0 /home/bart/uv/destructor.php(11): Fiber->start()
#1 /home/bart/uv/destructor.php(15): class@anonymous->__destruct()
#2 {main}
thrown in /home/bart/uv/destructor.php on line 11
Process finished with exit code 255
```
But I expected this output instead:
```
int(42)
```
### PHP Version
PHP 8.1.6
### Operating System
Ubuntu 20.04