Skip to content
Advertisement

Error generated by named arguments and argument unpacking in function call not throwing ErrorException in PHP-8

The following code works as expected: throws the ErrorException and calls the shutdown function for the fatal-error generated by require

register_shutdown_function(function() {
    echo "anyway, hello worldn";
});

set_error_handler(function($severity, $message, $file, $line) {
    throw new ErrorException($message, 0, $severity, $file, $line);
});

set_exception_handler(function($exception) {
    echo $exception->getMessage().PHP_EOL;
});

require "unavailable_file";

Output:

require(unavailable_file): Failed to open stream: No such file or directory

anyway, hello world

But fatal error generated by named arguments fails to call the exception-handler and the shutdown function

// replacing require in the previous code with the following

function foo() {}

foo(...[], bar: "baz");

Output:

Fatal error: Cannot combine named arguments and argument unpacking

Combining all of them also is not working as expected and the ErrorException from require is not caught

// ... 

require "unavailable_file";

function foo() {}

foo(...[], bar: "baz");

Output:

Fatal error: Cannot combine named arguments and argument unpacking

So is this another bug or am I missing something here?

PS: The PHP version is 8.0.0RC2 (cli)

Advertisement

Answer

As pointed out in the comments, it was indeed the case of different fatal type of fatal errors.

Since this falls under the category “generated before script is executed”, unfortunately the shutdown function will never be called. Too bad I did’t find anything showing which fatal errors fall under this category.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement