开放的编程资料库

当前位置:我爱分享网 > PHP教程 > 正文

PHP error_reporting() 备忘单

错误处理在任何编程语言中都很重要,PHP 也不例外。幸运的是,PHP 中的错误处理非常容易设置。以下是 PHP 的快速备忘单,直接来自 PHP.net。

错误级别

error_reporting() 函数中可以使用以下值和常量。

常数
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR

基本用法

下面是PHP报错的基本用法(只用了一级)。

//show nothing
error_reporting(0);

//show everything
error_reporting(E_ALL);

//using php.ini and ini_set()
ini_set('error_reporting', E_ALL);

高级用法

以下说明了多个错误报告级别。

//show warnings and errors
error_reporting(E_ERROR | ERROR_WARNING);

//show all types but notices
error_reporting(E_ALL ^ E_NOTICE);

自定义错误处理

请访问我的文章 PHP 中的自定义错误处理,了解 PHP 中的自定义错误处理。

上一个错误

要获取有关上一个错误的信息,您可以编写代码:

//returns an array with error number, message, file, and line
error_get_last();
未经允许不得转载:我爱分享网 » PHP error_reporting() 备忘单

感觉很棒!可以赞赏支持我哟~

赞(0) 打赏