如何查找错误的行号和文件名


How to find line number and file name of error

默认情况下,PHP在error_log文件中记录几种类型的错误,但我使用的是自定义错误函数

<?php set_error_handler("customError",E_ALL);
function customError($errno, $errstr)
{
 $e=$errno . ",". $errstr;  
 error_log($e);
 die( '<h4>An Error occurred.Don't worry just <a href="javascript:location.reload(true);">Refresh this Page</a>. </h4>');
}

我想在错误日志文件中记录行号和脚本名称。上面的代码只记录错误号和错误字符串。如何使用上面的代码记录脚本名称和错误行号。

您的自定义错误函数可以捕获文件和行作为参数:

function customError($errno, $errstr, $errfile, $errline) {
    $e=$errno . ",". $errstr . "," . $errfile . "," . $errline;
    ...
}

来自手册:

带有以下信号的回调。可以传递NULL,以将此处理程序重置为默认状态。

布尔处理程序(int$errno,string$errstr[,string$errfile[,int$errline[,array$errcontext]]])