我可以使用set\u error\u handler()捕获大多数PHP错误,但对于致命(E\u error)错误,例如调用不存在的函数,它不起作用。有没有其他方法可以捕捉这些错误
我正在尝试调用mail()查找所有错误,并且正在运行PHP5.2.3
使用需要PHP 5.2+的注册关闭函数记录致命错误:
注册关闭功能(“致命处理程序”);
函数fatal_handler(){
$errfile=“未知文件”;
$errstr=“关机”;
$errno=E_CORE_错误;
$errline=0;
$error=error_get_last();
如果($error!==NULL){
$errno=$error[“type”];
$errfile=$error[“file”];
$errline=$error[“line”];
$errstr=$error[“message”];
错误邮件(格式错误($errno,$errstr,$errfile,$errline));
}
}
您必须定义error\u mail和format\u error功能。例如:
函数格式\u错误($errno,$errstr,$errfile,$errline){
$trace=print\u r(debug\u backtrace(false),true);
$content=”
<;表格>;
<;thead>;<;th>;项目<;/th>;<;th>;说明<;/th>;<;/thead>;
<;t车身>;
<;tr>;
<;th>;错误<;/th>;
<;td>;<;pre>;$errstr<;/pre>;<;/td>;
<;/tr>;
<;tr>;
<;th>;Errno<;/th>;
<;td>;<;pre>;$errno<;/pre>;<;/td>;
<;/tr>;
<;tr>;
<;th>;文件<;/th>;
<;td>;$errfile<;/td>;
<;/tr>;
<;tr>;
<;th>;行<;/th>;
<;td>;$errline<;/td>;
<;/tr>;
<;tr>;
<;th>;跟踪<;/th>;
<;td>;<;pre>;$trace<;/pre>;<;/td>;
<;/tr>;
<;/t车身>;
<;/table>;“;
返回$content;
}
使用Swift Mailer编写错误邮件功能
另见:
- $php\u errormsg
- 预定义常数