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

yipeiwu_com6年前PHP代码库

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 写入日志操作就可以了

相关文章

win10 apache配置虚拟主机后localhost无法使用的解决方法

win10 apache配置虚拟主机后localhost无法使用的解决方法

win10系统配置虚拟主机 1.用记事本或Sublime Text打开httpd.conf ctrl + f 搜索httpd-vhosts.conf 将 #Include conf...

PHP简单实现冒泡排序的方法

本文实例讲述了PHP简单实现冒泡排序的方法。分享给大家供大家参考,具体如下: <?php $files = array("file11.txt","file22.txt...

PHP删除数组中的特定元素的代码

比如下面的程序: 复制代码 代码如下: <?php $arr = array('apple','banana','cat','dog'); unset($arr[2]); prin...

PHP自动选择 连接本地还是远程数据库

Mysql.class.php 文件见 https://www.jb51.net/article/25496.htm复制代码 代码如下: <?php // 包含Mysql操作类 i...

PHP中strpos、strstr和stripos、stristr函数分析

本文为大家分析了 PHP中strpos、strstr和stripos、stristr函数,供大家参考,具体内容如下 strpos mixed strpos ( string $hayst...