rfc:error_backtraces

This is an old revision of the document!


PHP RFC: Your Title Here

Introduction

PHP errors, unlike exceptions, are much more limited in programmers' ability to control their handling and get detailed information about them. I propose to fix some of these issues by recording a backtrace for every error.

While it's possible to somewhat address this with set_error_handler() and register_shutdown_function(),

Proposal

Introduce a new INI setting, debug_backtraces that allows to turn this feature on and off, as well as to limit the number of stack frames outputted. Zero would mean no backtraces, a positive value means output this number of frames, negative value for no limit. By default it would be on in development settings but off in production. People who don't want to have the overhead of having to generate backtraces in production can disable this functionality

Error output: traces will be formatted exactly like for exceptions, e.g.:

Fatal error: Allowed memory size of 134217728 bytes exhausted in /var/www/test.php on line 123
#0 /var/www/test.php(123): spl_eat_all_memory()
#1 /var/www/foo.php(456): foo(123, 'foo')
#2 /var/www/bar.php(789): bar()
#3 {main}

Backward Incompatible Changes

Everything will behave exactly as before with backtraces disabled, while turning them on would introduce a few minor changes to how errors are represented. Should not be a problem.

Proposed PHP Version(s)

8.0

php.ini Defaults

For error_backtraces:

  • Default value: 0
  • php.ini-development value: 100
  • php.ini-production value: 0

Open Issues

Make sure there are no open issues when the vote starts!

Unaffected PHP Functionality

Everything other the minor stuff mentioned in Backward Incompatible Changes.

Future Scope

Backtrace handling code could use some unification and refactoring, but that doesn't require a RFC and thus can be addressed later.

Proposed Voting Choices

Accept this RFC (yes/no)?

Patches and Tests

  • WIP patch:

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/error_backtraces.1590528585.txt.gz · Last modified: 2020/05/26 21:29 by maxsem