E_ERROR
PHPFATALCriticalError Levels

Fatal runtime error — script halted

Quick Answer

Use register_shutdown_function to detect fatal errors; fix the underlying cause (missing class, memory exhausted, etc.).

What this means

A fatal E_* error level constant that causes script termination. Cannot be caught with try-catch; handle via register_shutdown_function.

Why it happens
  1. 1Calling a non-existent function
  2. 2Allowed memory size exhausted

Fix

Catch fatal with shutdown function

Catch fatal with shutdown function
register_shutdown_function(function () {
    $err = error_get_last();
    if ($err && in_array($err['type'], [E_ERROR, E_PARSE, E_CORE_ERROR], true)) {
        http_response_code(500);
        // log $err['message'], $err['file'], $err['line']
    }
});

Why this works

Shutdown functions run even after fatal errors and can inspect the last error with error_get_last().

Code examples
E_* constants hierarchyphp
// E_ERROR     = 1   fatal, script stopped
// E_WARNING   = 2   non-fatal, script continues
// E_NOTICE    = 8   informational
// E_DEPRECATED = 8192  deprecated usage
// E_ALL       = all of the above
Increase memory limitphp
ini_set('memory_limit', '256M');
// or in php.ini: memory_limit = 256M
Same error in other languages

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PHP errors