命名参数生成的错误和函数调用中的参数解包不会在 PHP-8 中抛出 ErrorException
Error generated by named arguments and argument unpacking in function call not throwing ErrorException in PHP-8
以下代码按预期工作:抛出 ErrorException 并为 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";
输出:
require(unavailable_file): Failed to open stream: No such file or directory
anyway, hello world
但是命名参数产生的致命错误无法调用异常处理程序和关闭函数
// replacing require in the previous code with the following
function foo() {}
foo(...[], bar: "baz");
输出:
Fatal error: Cannot combine named arguments and argument unpacking
将它们全部组合起来也没有按预期工作,require
中的 ErrorException
未被捕获
// ...
require "unavailable_file";
function foo() {}
foo(...[], bar: "baz");
输出:
Fatal error: Cannot combine named arguments and argument unpacking
这是另一个错误还是我在这里遗漏了什么?
PS: PHP 版本为 8.0.0RC2 (cli)
正如评论中指出的那样,确实是不同致命类型的致命错误的情况。
由于这属于“在执行脚本之前生成”的类别,不幸的是永远不会调用关闭函数。太糟糕了,我没有找到任何显示哪些致命错误属于此类的信息。
是的,事实证明这不是错误!
E_COMPILE_ERROR
类型的错误
Fatal compile-time errors. This is like an E_ERROR, except it is
generated by the Zend Scripting Engine
还有E_PARSE
Compile-time parse errors. Parse errors should only be generated by
the parser
是这种行为的唯一原因(加上如果进程被 SIGTERM 或 SIGKILL 信号终止,或者 exit
或 die
在关闭函数之前被调用)
这是此类错误的列表
- https://3v4l.org/oO4L7 => 函数的重新声明
- https://3v4l.org/cNHbu =>
private
抽象方法
- https://3v4l.org/jPpIU => 访问级别必须相同或限制较少
以下代码按预期工作:抛出 ErrorException 并为 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";
输出:
require(unavailable_file): Failed to open stream: No such file or directory
anyway, hello world
但是命名参数产生的致命错误无法调用异常处理程序和关闭函数
// replacing require in the previous code with the following
function foo() {}
foo(...[], bar: "baz");
输出:
Fatal error: Cannot combine named arguments and argument unpacking
将它们全部组合起来也没有按预期工作,require
中的 ErrorException
未被捕获
// ...
require "unavailable_file";
function foo() {}
foo(...[], bar: "baz");
输出:
Fatal error: Cannot combine named arguments and argument unpacking
这是另一个错误还是我在这里遗漏了什么?
PS: PHP 版本为 8.0.0RC2 (cli)
正如评论中指出的那样,确实是不同致命类型的致命错误的情况。
由于这属于“在执行脚本之前生成”的类别,不幸的是永远不会调用关闭函数。太糟糕了,我没有找到任何显示哪些致命错误属于此类的信息。
是的,事实证明这不是错误!
E_COMPILE_ERROR
Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine
还有E_PARSE
Compile-time parse errors. Parse errors should only be generated by the parser
是这种行为的唯一原因(加上如果进程被 SIGTERM 或 SIGKILL 信号终止,或者 exit
或 die
在关闭函数之前被调用)
这是此类错误的列表
- https://3v4l.org/oO4L7 => 函数的重新声明
- https://3v4l.org/cNHbu =>
private
抽象方法 - https://3v4l.org/jPpIU => 访问级别必须相同或限制较少