设置错误报告以及显示它们的位置
如果它还没有在 php.ini 中完成,则可以动态设置错误报告,并且应该设置为允许显示大多数错误:
句法
int error_reporting ([ int $level ] )
例子
// should always be used prior to 5.4
error_reporting(E_ALL);
// -1 will show every possible error, even when new levels and constants are added
// in future PHP versions. E_ALL does the same up to 5.4.
error_reporting(-1);
// without notices
error_reporting(E_ALL & ~E_NOTICE);
// only warnings and notices.
// for the sake of example, one shouldn't report only those
error_reporting(E_WARNING | E_NOTICE);
默认情况下,php 会记录错误,通常位于与运行脚本相同级别的 error.log 文件中。
在开发环境中,还可以在屏幕上显示它们:
ini_set('display_errors', 1);
然而,在生产中,应该
ini_set('display_errors', 0);
并通过使用异常或错误处理程序显示友好的问题消息。