如何使用PHP的error_get_last函数调试
很多php的空间都没有开启PHP调试,这就导致我们使用一些基础函数时候,没有办法知道程序倒底发生了什么事。
此时我们就可以使用error_get_last() 函数获取最后发生的错误。
该函数以数组的形式返回最后发生的错误。
返回的数组包含 4 个键和值:
[type] - 错误类型
[message] - 错误消息
[file] - 发生错误所在的文件
[line] - 发生错误所在的行
语法
error_get_last()
例子
<?php
echo $test;
print_r(error_get_last());
?>
输出:
Array
(?
[type] => 8
[message] => Undefined variable: test
[file] => C:\webfolder\test.php
[line] => 2
)

