{
    "slug": "php_error_levels",
    "term": "PHP Error Levels & error_reporting",
    "category": "php",
    "difficulty": "intermediate",
    "short": "PHP's graduated error severity system from E_NOTICE to E_ERROR, controlled by error_reporting and display_errors INI directives.",
    "long": "PHP errors span multiple levels: E_ERROR (fatal, stops execution), E_WARNING (non-fatal runtime), E_NOTICE (minor runtime hints), E_DEPRECATED, E_STRICT (coding standards), E_PARSE (compile-time syntax), and the aggregate E_ALL. error_reporting = E_ALL is the correct development setting — it surfaces E_NOTICE and E_DEPRECATED issues that become real bugs. display_errors must be Off in production (log instead). set_error_handler() registers a custom handler to convert errors to exceptions or structured log entries. PHP 8.0 promotes many warnings to TypeErrors, making strict typing even more valuable.",
    "aliases": [
        "PHP error reporting",
        "E_ALL",
        "E_NOTICE",
        "error_reporting()"
    ],
    "tags": [
        "php",
        "debugging",
        "configuration",
        "quality"
    ],
    "misconception": "Setting error_reporting(0) in production is a valid security measure. Hiding errors does not prevent them — it makes debugging nearly impossible and can mask security-relevant failures. Log errors to a file with display_errors=Off and log_errors=On instead.",
    "why_it_matters": "PHP's error level bitmask controls which errors are reported and logged — running production with E_ALL hidden masks bugs; running development without E_DEPRECATED misses upgrade-breaking changes.",
    "common_mistakes": [
        "Setting error_reporting = 0 in development — hides all errors and makes debugging impossible.",
        "Not enabling E_DEPRECATED — deprecated function calls are silent until the version that removes them.",
        "Using display_errors = On in production — leaks file paths, stack traces, and database structure to users.",
        "Not converting errors to exceptions with set_error_handler() — errors and exceptions get handled inconsistently."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "error_handling",
        "php_ini",
        "information_disclosure",
        "exception_handling"
    ],
    "prerequisites": [
        "error_handling",
        "php_ini",
        "static_analysis"
    ],
    "refs": [
        "https://www.php.net/manual/en/errorfunc.constants.php",
        "https://www.php.net/manual/en/function.set-error-handler.php"
    ],
    "bad_code": "# php.ini — production with errors displayed:\nerror_reporting = E_ALL\ndisplay_errors = On   ; Never in production — use log_errors = On instead\nlog_errors = Off      ; Errors not logged — invisible failures",
    "good_code": "; php.ini — development: show everything\nerror_reporting = E_ALL\ndisplay_errors = On\nlog_errors = On\n\n; php.ini — production: log, never display\nerror_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT\ndisplay_errors = Off\nlog_errors = On\nerror_log = /var/log/php/error.log\n\n// PHP — set at runtime (overrides php.ini)\nerror_reporting(E_ALL);\nset_error_handler(function(int $errno, string $errstr, string $file, int $line): bool {\n    if (!(error_reporting() & $errno)) return false; // respect @ operator\n    throw new \\ErrorException($errstr, 0, $errno, $file, $line);\n});\n\n// Convert all errors to exceptions — makes them catchable and loggable",
    "quick_fix": "Set error_reporting(E_ALL) in development to see every notice and deprecation — these are bugs waiting to become errors in the next PHP version",
    "severity": "medium",
    "effort": "low",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_error_levels",
        "html_url": "https://codeclaritylab.com/glossary/php_error_levels",
        "json_url": "https://codeclaritylab.com/glossary/php_error_levels.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[PHP Error Levels & error_reporting](https://codeclaritylab.com/glossary/php_error_levels) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_error_levels"
            }
        }
    }
}