Warning: Never display any error messages in a production environment! (Recommended learning: PHP video tutorial)
Display errors (display_errors) and error reporting (error_reporting) are two different things. When an error occurs in a PHP script, you can choose whether to report the error (record it in the error log) according to the settings. If display_errors is turned on in the settings, the error message will be printed to the screen at the same time.
Commonly used settings in projects
switch (ENVIRONMENT) { // 对于开发环境,报告所有错误,同时显示到屏幕上 case 'development': error_reporting(-1); ini_set('display_errors', 1); break; // 对于测试和生产环境,不显示错误,5.3 以上的版本,不报告通知、废弃方法、严格这几类错误 case 'testing': case 'production': ini_set('display_errors', 0); if (version_compare(PHP_VERSION, '5.3', '>=')) { error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); } else { error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); } break; default: header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); echo 'The application environment is not set correctly.'; exit(1); // EXIT_ERROR }
Modify the php.ini configuration file
error_reporting = E_ALL # 报告所有错误 display_errors = On # 显示错误
The above is the detailed content of php error display configuration. For more information, please follow other related articles on the PHP Chinese website!