Home > Backend Development > PHP Problem > php error display configuration

php error display configuration

(*-*)浩
Release: 2023-02-26 13:18:01
Original
3065 people have browsed it

php error display configuration

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
}
Copy after login

Modify the php.ini configuration file

error_reporting = E_ALL # 报告所有错误
display_errors = On # 显示错误
Copy after login

The above is the detailed content of php error display configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template