[php-src] Issue #10695: set_exception_handler must catch exceptions also when in shutdown
| From: | mvorisek | Date: | Fri, 24 Feb 2023 21:39:36 +0000 |
| Subject: | [php-src] Issue #10695: set_exception_handler must catch exceptions also when in shutdown | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243801@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10695
Author: mvorisek
### Description
The following code:
<details>
<summary>click to expand</summary>
```php
<?php
set_exception_handler(function (\Throwable $exception) {
echo 'Caught: ' . $exception->getMessage() . "\n";
});
set_error_handler(static function (int $severity, string $msg, string $file, int $line): bool {
if ((error_reporting() & ~(\PHP_MAJOR_VERSION >= 8 ? 4437 : 0)) === 0) {
return false;
}
echo 'Caught error: ' . $msg . "\n";
return true;
});
register_shutdown_function(function () {
trigger_error('warn_shutdown_1', \E_USER_WARNING);
});
register_shutdown_function(function () {
trigger_error('warn_shutdown_2', \E_USER_WARNING);
});
register_shutdown_function(function () {
throw new \Exception('ex_shutdown_1');
});
register_shutdown_function(function () {
// expected to be never executed as after 1 uncaught exception php invokes shutdown,
// after 1 uncaught exception in shutdown, php terminates
throw new \Exception('ex_shutdown_2');
});
trigger_error('warn_regular_1', \E_USER_WARNING);
trigger_error('warn_regular_2', \E_USER_WARNING);
throw new \Exception('ex_regular');
```
</details>
https://3v4l.org/lXRcY
Resulted in this output:
```
Caught error: warn_regular_1
Caught error: warn_regular_2
Caught: ex_regular
Caught error: warn_shutdown_1
Caught error: warn_shutdown_2
Fatal error: Uncaught Exception: ex_shutdown_1 in /in/lXRcY:24
Stack trace:
#0 [internal function]: {closure}()
#1 {main}
thrown in /in/lXRcY on line 24
```
But I expected this output instead:
```
Caught error: warn_regular_1
Caught error: warn_regular_2
Caught: ex_regular
Caught error: warn_shutdown_1
Caught error: warn_shutdown_2
Caught: ex_shutdown_1
```
restore_error_handler is working in shutdown, set_exception_handler must
work too
### PHP Version
any
### Operating System
any