我的脚本有以下代码:
set_error_handler(function(int $severity, string $message, string $filename, int $lineNumber) : void {
throw new ErrorException($message, 0, $severity, $filename, $lineNumber);
});
function test() : string {
return $test;
}
test();在PHP7.3.11上运行脚本(在macOS 10.15.7上)将按预期工作,并显示如下内容:
致命错误:未定义的ErrorException:未定义变量:./index.php中的测试:9堆栈跟踪:
#0 ./index.php(9):{闭包}(8,‘未定义的varia.’,‘.’,9,Array)
#1 ./index.php(12):test()
#2 {main}
下一步TypeError: test()的返回值必须是字符串类型,在./index.php:9 Stack跟踪中返回null:
#0 ./index.php(12):test()
#1 {main}抛入第9行中的./index.php
但是在PHP-8 (php:8.0.0rc1-apache对接者图像)上,它被卡在一个循环上,什么也不显示。
不过,删除set_error_handler是可行的。
警告:第9行./index.php中未定义的变量$test
致命错误: Uncaught : test():返回值必须是字符串类型,在./index.php:9中返回null
堆栈跟踪:
#0 ./index.php(12):test()
#1 {main}抛入第9行中的./index.php
这是一个bug,还是在新版本中做了一些更改?我在上试了一下。
发布于 2020-10-17 03:35:03
正如注释中指出的那样,它确实是一个错误,并且已经在第二个版本候选版本(PHP-8.0.0 RC2)中得到了解决。
https://stackoverflow.com/questions/64247365
复制相似问题