欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php error_reporting() 设置错误报告级别

程序员文章站 2022-05-17 09:37:15
...
  1. * For now, avoid warnings of E_STRICT mode
  2. * (this must be done before function definitions)
  3. */
  4. if (defined(’E_STRICT’)) {
  5. $old_error_reporting = error_reporting(0);
  6. if ($old_error_reporting & E_STRICT) {
  7. error_reporting($old_error_reporting ^ E_STRICT);
  8. } else {
  9. error_reporting($old_error_reporting);
  10. }
  11. unset($old_error_reporting);
复制代码

常见的如下:

  1. // Turn off all error reporting;关闭所有的错误

  2. error_reporting(0);
  3. // Report simple running errors;报告一个简单的运行错误

  4. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  5. // Reporting E_NOTICE can be good too (to report uninitialized

  6. // variables or catch variable name misspellings …);包括报告一些未初始化的变量或捕捉变量名的拼写错误
  7. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

  8. // Report all errors except E_NOTICE
  9. // This is the default value set in php.ini;报告所有的错误但不包括E_NOTICE
  10. error_reporting(E_ALL ^ E_NOTICE);

  11. // Report all PHP errors (bitwise 63 may be used in PHP 3);报告所有的错误
  12. error_reporting(E_ALL);

  13. // Same as error_reporting(E_ALL);同上
  14. ini_set(’error_reporting’, E_ALL);
复制代码