Article

PHP Error Handling Modernization

Replace display_errors-in-production habits with logging, Throwable-aware handlers, and migration-friendly treatment of deprecations.

Legacy apps often rely on display_errors=On and @ suppression. That combination hides problems in development noise and leaks internals in production. Modern error handling logs everything actionable, shows generic pages to users, and treats deprecations as upgrade fuel—not as ignored noise forever.

LEGACY — show everything publicly
MODERN — log in production
getMessage() . "
" . $e->getTraceAsString());
    http_response_code(500);
    echo 'An unexpected error occurred.';
});

During PHP upgrades

Run staging with deprecations logged (and ideally failing CI) while production remains stable. Fix deprecations in batches before they become fatals on the next runtime. Central handlers should accept Throwable, not only Exception, so PHP Error types are not missed.

Build ini bitmasks with the Error Reporting Generator. Compare environments via Environment Compare. Manual: Error handling.

Related reading