{
    "slug": "php_fatal_error",
    "term": "Fatal Errors vs Errors vs Warnings",
    "category": "php",
    "difficulty": "beginner",
    "short": "PHP has three error levels that behave very differently: fatal errors halt execution, warnings continue but signal problems, and notices are advisory only.",
    "long": "PHP's error system has multiple levels controlled by error_reporting(). Fatal errors (E_ERROR) stop execution immediately — you cannot catch them with try/catch, only with register_shutdown_function(). Parse errors (E_PARSE) prevent the file loading at all. Warnings (E_WARNING) continue execution but signal something wrong. Notices (E_NOTICE) are advisory — undefined variables, deprecated usages. PHP 7 replaced many engine-level fatals with catchable Error exceptions.",
    "aliases": [
        "E_ERROR",
        "E_WARNING",
        "E_NOTICE",
        "E_PARSE"
    ],
    "tags": [
        "error-handling",
        "runtime",
        "debugging"
    ],
    "misconception": "Fatal errors can be caught with try/catch — they cannot in PHP 5; in PHP 7+ many are now catchable Error exceptions, but true E_ERROR still terminates the process.",
    "why_it_matters": "Understanding error levels determines how your error handler and monitoring behave — a swallowed notice today can be a production outage tomorrow.",
    "common_mistakes": [
        "Suppressing all errors with error_reporting(0) hiding real bugs",
        "Not distinguishing Error exceptions (catchable) from true fatals (not catchable)",
        "Logging warnings at same severity as fatals in monitoring"
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "exception_handling",
        "php_error_levels",
        "error_handling"
    ],
    "prerequisites": [
        "exception_handling",
        "php_error_levels"
    ],
    "refs": [
        "https://www.php.net/manual/en/errorfunc.constants.php"
    ],
    "bad_code": "// Fatal errors were uncatchable in PHP 5:\nrequire 'nonexistent.php'; // Fatal — script dies, no catch possible\ncall_to_undefined_function(); // Fatal",
    "good_code": "// PHP 7+: most fatals are now catchable Errors:\ntry {\n    require 'nonexistent.php';\n} catch (\\Error $e) {\n    echo 'Fatal caught: ' . $e->getMessage();\n}\n\n// Register shutdown for truly uncatchable fatals:\nregister_shutdown_function(function() {\n    $error = error_get_last();\n    if ($error && $error['type'] === E_ERROR) {\n        error_log('Fatal: ' . $error['message']);\n    }\n});",
    "quick_fix": "Set error_reporting(E_ALL) in development and use set_error_handler() to convert warnings/notices to exceptions so nothing is silently swallowed",
    "severity": "high",
    "effort": "low",
    "created": "2026-03-22",
    "updated": "2026-03-23",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_fatal_error",
        "html_url": "https://codeclaritylab.com/glossary/php_fatal_error",
        "json_url": "https://codeclaritylab.com/glossary/php_fatal_error.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": "[Fatal Errors vs Errors vs Warnings](https://codeclaritylab.com/glossary/php_fatal_error) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_fatal_error"
            }
        }
    }
}