Skip to content

set_exception_handler not restored if calling exit within itself #18619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kkmuffme opened this issue May 21, 2025 · 0 comments
Open

set_exception_handler not restored if calling exit within itself #18619

kkmuffme opened this issue May 21, 2025 · 0 comments

Comments

@kkmuffme
Copy link

Description

What was fixed 3301d96 #13446 (comment) bc it was broken from 8.3.0-8.3.4 is still broken if the exception handler itself calls exit.

https://3v4l.org/HkWfh
without exit: https://3v4l.org/FTWQf

The following code:

<?php

declare(strict_types=1);

function foo($e) {
    var_dump( set_exception_handler('foo') );
    restore_exception_handler();
    echo "---" . PHP_EOL;
    exit;
}

set_exception_handler('foo');

register_shutdown_function(function () {
    var_dump( set_exception_handler(null) );
});

strlen(null);

Resulted in this output:

NULL
---
NULL

But I expected this output instead:

NULL
---
string(3) "foo"

This matters, because since PHP 8.3, the exit code of the exit() call in exception handler is used as exit code of PHP

@iluuu1994

PHP Version

PHP 8.3.0+

Operating System

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant