gpt4 book ai didi

尽管 error_handling = 1 PHP error_get_last 得到警告

转载 作者:行者123 更新时间:2023-12-03 08:07:35 24 4
gpt4 key购买 nike

所以在 php.ini 中我设置了:

error_reporting  =  E_ERROR

我写了一个处理程序:
register_shutdown_function( "fatal_handler" );

function fatal_handler() {

$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;

$error = error_get_last();

if( $error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];

if($errno == E_ERROR){
$html = 'some html here';
print($html);
die();
}
}
}

我为测试它所做的就是在一个脚本中放置比 max_execution_time 更长的 sleep 时间。出于某种原因,如果我在加载故意损坏的页面时在不同的选项卡中打开一个新页面,这也会杀死其他页面。没关系,但是当第二页崩溃时,它会给我一个 error_get_last() 警告。但我将 error_reporting 设置为 1!为什么它向我显示警告?它不会记录它,但它会导致我无法捕捉到导致白屏的错误,这正是这段代码应该避免的事情!

最佳答案

关闭处理程序和 error_get_last 都不尊重 error_reporting。

无论任何错误或它的级别如何,都会始终调用关闭处理程序(除非您在自定义错误处理程序内抛出异常)

error_get_last 只是给你最后一个错误,不管它的级别。

为什么不使用关闭处理程序,而不是使用错误处理程序?在这种情况下,如果您想忽略该级别的错误,您可以检查错误级别并返回 FALSE。 (返回 FALSE 告诉 PHP 正常进行)

set_error_handler("fatal_handler");

function fatal_handler($errno, $errstr, $errfile, $errline, $errctx)
{
$reptLevel = error_reporting();

if ($reptLevel > 0) //if $reptLevel = 0 then it means the code that caused the error was preceded by a supressor (example: $x = @someFunction())
{
if ($errno == E_ERROR)
{
$html = 'some html here';
print($html);
die();
} else {
return false;
}
}
}

关于尽管 error_handling = 1 PHP error_get_last 得到警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25633104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com