您的位置:首页 > 编程语言 > PHP开发

PHP函数补完:error_reporting()

2011-01-01 00:00 267 查看
error_reporting() 设置 PHP 的报错级别并返回当前级别。

语法:error_reporting(report_level)

如果参数 level 未指定,当前报错级别将被返回。下面几项是 level 可能的值:

; 错误报告是按位的。或者将数字加起来得到想要的错误报告等级。  

; E_ALL - 所有的错误和警告  

; E_ERROR - 致命性运行时错  

; E_WARNING - 运行时警告(非致命性错)  

; E_PARSE - 编译时解析错误  

; E_NOTICE - 运行时提醒(这些经常是是你的代码的bug引起的, 

;也可能是有意的行为造成的。(如:基于未初始化的变量自动初始化为一个  

              ;空字符串的事实而使用一个未初始化的变量) 

; E_CORE_ERROR - 发生于PHP启动时初始化过程中的致命错误  

; E_CORE_WARNING - 发生于PHP启动时初始化过程中的警告(非致命性错)  

; E_COMPILE_ERROR - 编译时致命性错  

; E_COMPILE_WARNING - 编译时警告(非致命性错)  

; E_USER_ERROR - 用户产生的出错消息  

; E_USER_WARNING - 用户产生的警告消息  

; E_USER_NOTICE - 用户产生的提醒消息 

任意数目的以上选项都可以用“或”来连接(用 OR 或 |),这样可以报告所有需要的各级别错误。例如,下面的代码关闭了用户自定义的错误和警告,执行了某些操作,然后恢复到原始的报错级别:

<?php
//禁用错误报告
error_reporting(0);
//报告运行时错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//报告所有错误
error_reporting(E_ALL);
?>

<?php
error_reporting(255);	// 列出所有提示
error_reporting(0);		// 不显示所有提示
error_reporting(7);		// 建议使用
?>

更详细可以参照下表:

常量描述
1E_ERRORFatal run-time errors. Errors that can not be recovered from. Execution of the script is halted 致命的运行时错误
2E_WARNINGNon-fatal run-time errors. Execution of the script is not halted 运行时警告(非致命性错误)
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser 编译时解析错误
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally 运行时提醒(经常是bug,也可能是有意的)
16E_CORE_ERRORFatal errors at PHP startup. This is like an E_ERROR in the PHP core PHP启动时初始化过程中的致命错误
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like an E_WARNING in the PHP core PHP启动时初始化过程中的警告(非致命性错)
64E_COMPILE_ERRORFatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine 编译时致命性错
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine 编译时警告(非致命性错)
256E_USER_ERRORFatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error() 用户自定义的致命错误
512E_USER_WARNINGNon-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error() 用户自定义的警告(非致命性错误)
1024E_USER_NOTICEUser-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error() 用户自定义的提醒(经常是bug,也可能是有意的)
2048E_STRICTRun-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code 编码标准化警告(建议如何修改以向前兼容)
4096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler()) 接近致命的运行时错误,若未被捕获则视同E_ERROR
8191E_ALLAll errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0) 除E_STRICT外的所有错误(PHP6中为8191,即包含所有)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息