Skip to content

set_exception_handler not restored if calling exit within itself #18619

Open
@kkmuffme

Description

@kkmuffme

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions