首页  新闻动态  文化知识  网络文摘  生活时尚  娱乐休闲  健康频道  外语学习  软件教学  程序设计  独山图片  书店网站 
  程序设计 > Javascript/PHP > 正文
 

PHP错误报告开启和关闭的实现

来源:互联网 [2013-05-06]   浏览次数:4233
定义和用法
error_reporting() 设置 php 的报错级别并返回当前级别。

语法
int error_reporting ([ int $level ] )如果参数 level 未指定,当前报错级别将被返回。下面几项是 level 可能的值


<?php

//关闭所有的错误报告
error_reporting(0);

//只报告运行错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);

//报告E_NOTICE
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

//报告所有的运行错误,除了e_notice
//这是php.ini的默认值
error_reporting(E_ALL ^ E_NOTICE);

//报告所有的php错误
error_reporting(E_ALL);

//报告所有的php错误
error_reporting(-1);

//和error_reporting(e_all)有一样的功效,该设置也会报告所有php错误
ini_set('error_reporting', E_ALL);

?>

注:为了安全,我们可以关闭错误报告,关闭后若程序出现错误将显示空白页,将不会有任何错误提示,但调试程序时不建议使用。

值 常量 描述
1 e_error fatal run-time errors. errors that can not be recovered from. execution of the script is halted
2 e_warning non-fatal run-time errors. execution of the script is not halted
4 e_parse compile-time parse errors. parse errors should only be generated by the parser
8 e_notice run-time notices. the script found something that might be an error, but could also happen when running a script normally
16 e_core_error fatal errors at php startup. this is like an e_error in the php core
32 e_core_warning non-fatal errors at php startup. this is like an e_warning in the php core
64 e_compile_error fatal compile-time errors. this is like an e_error generated by the zend scripting engine
128 e_compile_warning non-fatal compile-time errors. this is like an e_warning generated by the zend scripting engine
256 e_user_error fatal user-generated error. this is like an e_error set by the programmer using the php function trigger_error()
512 e_user_warning non-fatal user-generated warning. this is like an e_warning set by the programmer using the php function trigger_error()
1024 e_user_notice user-generated notice. this is like an e_notice set by the programmer using the php function trigger_error()
2048 e_strict run-time notices. php suggest changes to your code to help interoperability and compatibility of the code
4096 e_recoverable_error catchable fatal error. this is like an e_error but can be caught by a user defined handle (see also set_error_handler())
8191 e_all all errors and warnings, except level e_strict (e_strict will be part of e_all as of php 6.0)

参见 《PHP手册》
>>上篇:已经没有了
>>下篇:PHP中对HTML代码的处理的常用函数
 
 
版权所有:独山在线 copyright ©2007-2024 www.dushan.net, All Rights Reserved.
   免责声明:本网转载或链接出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。
   本站为公益性网站,旨在宣传独山,如有侵犯请和我们联系,经查实将及时删除! 工信部备案:黔ICP备07001263号-3