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

176 views Asked by At

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 world\n";
});

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)

2

There are 2 answers

0
AudioBubble On BEST 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.

0
Rain On

Yes, it turns out this is not a bug!

Errors of type E_COMPILE_ERROR

Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine

And also E_PARSE

Compile-time parse errors. Parse errors should only be generated by the parser

Are the only reason for such behavior (plus if the process is killed with a SIGTERM, or SIGKILL signal or exit or die were called before the shutdown function)

Here is a list of such errors

  1. https://3v4l.org/oO4L7 => Redeclaration of a function
  2. https://3v4l.org/cNHbu => private abtract methods
  3. https://3v4l.org/jPpIU => Acess level must be the same or less restrictive