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

时间:2013-07-09 07:07:25

标签: php

默认情况下,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>');
}

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

1 个答案:

答案 0 :(得分:4)

您的自定义错误功能可以将文件和行捕获为参数:

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

来自Manual

  

使用以下siganture进行回调。可以传递NULL,以将此处理程序重置为其默认状态。

     

bool handler(int $ errno,string $ errstr [,string $ errfile [,int $ errline [,array $ errcontext]]])