Home  >  Article  >  Backend Development  >  探讨捕获php错误信息方法的详解_php技巧

探讨捕获php错误信息方法的详解_php技巧

WBOY
WBOYOriginal
2016-05-17 09:02:12778browse

PS:
1.捕获PHP语法错误
2.严重错误

用正常的 set_error_handle无法捕获此两类错误,这是捕获此类错误的技巧

复制代码 代码如下:

//test.php 页面
error_reporting(0);
register_shutdown_function('PageOnShutdown');
include('error_test.php');
function PageOnShutdown()
{
$msg = error_get_last();
print_r($msg);

}

//error_test.php 页面

$a = 1 + 2

$b


然后 输出 test.php 打印出
Array ( [type] => 4 [message] => parse error [file] => D:\web\tbc\error_test.php [line] => 5 )
再根据 获得 $msg 写入日志操作就可以了
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn