With PHP 8.5, a new fatal_error_backtraces setting can control whether a backtrace is shown for fatal errors. Fatal errors without backtraces in today's stable PHP versions (i.e., PHP 8.4) might include parse errors (syntax errors), duplicate functions or classes, infinite loops with a max execution time, etc.
For example, let's say we have this script that defines a class that is duplicated:
class A { public function loadClassB() { require 'b.php'; return new B(); }} class B {} class C { public function loadClassA() { return new A(); }} (new C())->loadClassA()->loadClassB();
Where b.php also defines a class B:
// b.phpclass B {};
If you run the code in PHP 8.4 or earlier, here's the output:
Fatal error: Cannot declare class B, because the name is already in usein /srv/app/b.php on line 3
Starting in PHP 8.5, you would get more helpful information that led to the fatal error. Clearly, this derrived example is easy to understand without the stack trace, but in a typical application, backtraces will be a huge help in fixing production errors:
Fatal error: Cannot redeclare class B (previously declared in /srv/app/index.php:11) in /srv/app/b.php on line 3Stack trace:#0 /srv/app/index.php(6): require()#1 /srv/app/index.php(21): A->loadClassB()#2 {main}
The INI setting default value is fatal_error_backtraces=1 in PHP 8.5, meaning this will be enabled by default. If, for some reason, you want to turn it off, you can set fatal_error_backtraces=0:
$ php -d fatal_error_backtraces=0 index.php Fatal error: Cannot redeclare class B (previously declared in /srv/app/index.php:11) in /srv/app/b.php on line 3
To learn more about this feature, check out the accepted and implemented RFC: rfc:error_backtraces_v2.