Kritim Yantra
Apr 25, 2025
With PHP 8.5, debugging fatal errors is no longer a guessing game. Thanks to the brand-new fatal_error_backtraces
INI directive, PHP now provides full stack traces for fatal errors by default—helping developers trace the exact path that led to the crash.
Whether you're working on a large Laravel application or a simple script, this new feature is a game-changer for debugging and improving code reliability.
Before PHP 8.5, when your application hit a fatal error—like running out of memory or calling an undefined function—you'd see something like this:
Fatal error: Maximum execution time of 1 second exceeded in example.php on line 7
That’s it. No context. No backtrace. You're left to manually trace the issue by scanning your code and adding temporary logging. Frustrating, right?
fatal_error_backtraces
Introduced in PHP 8.5, the fatal_error_backtraces
directive enables PHP to show stack traces even for unrecoverable E_ERROR
-level failures.
php.ini
, .htaccess
, or ini_set()
#[\SensitiveParameter]
and zend.exception_ignore_args
This new behavior gives you a clear view of the exact chain of function calls that led to the crash—making debugging much more efficient.
Let’s look at a recursive function that runs indefinitely:
<?php
set_time_limit(1);
function recurse(): void {
usleep(100000);
recurse();
}
recurse();
Fatal error: Maximum execution time of 1 second exceeded in example.php on line 7
fatal_error_backtraces = On
)Fatal error: Maximum execution time of 1 second exceeded in example.php on line 6
Stack trace:
#0 example.php(6): usleep(100000)
#1 example.php(7): recurse()
#2 example.php(7): recurse()
...
#11 {main}
Now you instantly see how your code crashed and exactly where it happened.
php.ini
fatal_error_backtraces = On ; Default
fatal_error_backtraces = Off ; To disable
<?php
ini_set('fatal_error_backtraces', '0');
This feature works smartly with other security-related settings:
#[\SensitiveParameter]
are hidden from backtraces.zend.exception_ignore_args = On
, function arguments are excluded from the trace.display_errors = Off
, backtraces won't be shown—ideal for production.Backtraces let you pinpoint where the fatal error occurred and how it was reached—without extra tools or custom handlers.
You can disable this feature or hide it in production by turning off display_errors
. No backward compatibility issues.
Error tracking tools and frameworks can hook into this mechanism to provide richer error reporting and safer debugging.
The feature was introduced through the RFC “Error Backtraces v2” and received overwhelming support (19–1 vote). It was implemented directly in the Zend Engine by adding a global to store fatal error backtraces.
With fatal_error_backtraces
in PHP 8.5, debugging fatal errors becomes a seamless and insightful experience. Whether you're developing APIs, working on legacy apps, or maintaining complex systems, this feature gives you immediate insight into what went wrong—saving hours of head-scratching.
✅ Upgrade to PHP 8.5 and start taking advantage of stack traces for fatal errors today.
#[\SensitiveParameter]
to protect sensitive user data.No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google