symfony/error-handler
Symfony ErrorHandler provides robust error and exception handling tools for PHP. Enable debug mode, register an error handler, and use DebugClassLoader for better stack traces. Convert PHP notices/warnings into exceptions and wrap risky code with ErrorHandler::call for safer debugging.
Pros:
Debug, ErrorHandler, and DebugClassLoader remain incrementally adoptable without full rewrite.App\Exceptions\Handler, logging (Monolog/Sentry), queues, and debugging tools (Debugbar/Telescope) remains intact.Kernel::VERSION usage (fix for #64102) reduces internal dependency risks and aligns with Symfony’s focus on minimalism.Cons:
try-catch, report()/render(), and debugbar unless used for specific gaps (e.g., deprecation warnings).Debug::enable() remain local-only; production still requires custom templates for user-facing errors.App\Exceptions\Handler::render() for custom error pages using HtmlErrorRenderer.ErrorHandler in bootstrap/app.php or a service provider./checkout) in ErrorHandler::call().dump-static-error-pages for offline error pages.composer require symfony/error-handler).Kernel::VERSION reduces internal versioning risks in Symfony 8.1+.symfony/debug).Kernel::VERSION (fix for #64102) reduces edge-case failures.Debug::enable() in production exposes stack traces (mitigate with custom templates).ErrorHandler::call() adds negligible latency (~microseconds).ErrorHandler::silenceDeprecations()).App\Exceptions\Handler (e.g., for deprecation warnings)?ErrorHandler::call() for resilience?Kernel::VERSION impact long-term compatibility with Laravel’s Symfony components?App\Exceptions\Handler for custom error rendering.ErrorHandler::call().dump-static-error-pages for offline error pages.Debug, ErrorHandler) with Symfony’s DebugBundle.Kernel::VERSION aligns with Symfony 8.1’s minimalist design.Phase 1: Critical Paths (Low Risk)
ErrorHandler::call().$data = ErrorHandler::call(function () {
return Stripe::charges()->create($params);
});
Phase 2: Debugging (Dev/Staging)
Debug::enable() in bootstrap/app.php for local/staging.Phase 3: Production Error Redaction
resources/views/errors/custom.blade.php) using HtmlErrorRenderer.App\Exceptions\Handler::render().Phase 4: CI/CD Enforcement (Optional)
- name: Check for unhandled errors
run: php artisan error-handler:test --paths=app/Http/Controllers
Phase 5: Legacy Code Modernization
ErrorHandler::silenceDeprecations(false) to log deprecation warnings during PHP upgrades.| Component | Laravel 10+ | PHP 8.2+ | Symfony 6/7/8 | Notes |
|---|---|---|---|---|
ErrorHandler::call() |
✅ Yes | ✅ Yes | ✅ All | Works with any Laravel version. |
Debug::enable() |
✅ Yes | ✅ Yes | ✅ All | Local/dev only. |
| Custom Templates | ✅ Yes | ✅ Yes | ✅ All | Requires Blade/Twig. |
| Static Error Pages | ✅ Yes | ✅ Yes | ✅ 7.3+ | Artisan command. |
| Deprecation Warnings | ✅ Yes | ⚠️ 8.0+ | ✅ 7.4+ | PHP 7.4+ for backported fixes. |
| Symfony 8.1+ Fix | ✅ Yes | ✅ Yes | ✅ 8.1+ | Kernel::VERSION removed. |
/checkout, API endpoints).@-silenced errors and ad-hoc try-catch with ErrorHandler::call().Kernel::VERSION removal) improve long-term stability.ErrorHandler::call() adds negligible performance cost.How can I help you explore Laravel packages today?