无涯教程-PHP错误处理函数 - error_reporting()
warning:
这篇文章距离上次修改已过204天,其中的内容可能已经有所变动。
error_reporting()
函数在 PHP 中用于设置应该报告何种错误。这个函数可以接受一个参数,该参数是一个位字段,表示了错误级别。
解决方案:
- 使用
error_reporting(E_ALL)
来报告所有错误。
error_reporting(E_ALL);
- 使用
error_reporting(E_ERROR | E_WARNING | E_PARSE)
来仅报告运行错误、警告和解析错误。
error_reporting(E_ERROR | E_WARNING | E_PARSE);
- 使用
error_reporting(0)
来关闭错误报告。
error_reporting(0);
- 使用
ini_set('display_errors', '1')
来在运行时显示错误。
ini_set('display_errors', '1');
- 使用
ini_set('display_errors', '0')
来在运行时关闭错误显示。
ini_set('display_errors', '0');
- 使用
error_reporting(E_ALL & ~E_NOTICE)
来报告所有错误,除了注意事项。
error_reporting(E_ALL & ~E_NOTICE);
注意:在生产环境中,应当关闭错误显示,以防止敏感信息泄露。在开发环境中,应当开启错误显示,以便快速发现和修复问题。
评论已关闭