rfc:error_backtraces_v2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:error_backtraces_v2 [2024/12/06 16:42] – forgot to bump version enorris | rfc:error_backtraces_v2 [2025/01/29 15:46] (current) – add link to implementation enorris | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Error Backtraces v2 ====== | ====== PHP RFC: Error Backtraces v2 ====== | ||
- | * Version: | + | * Version: |
* Date: 2024-12-05 | * Date: 2024-12-05 | ||
* Author: Eric Norris, erictnorris@gmail.com | * Author: Eric Norris, erictnorris@gmail.com | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
+ | * Implementation: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | PHP errors do not provide backtraces, which can make it difficult to ascertain their underlying cause. Enabling backtraces for certain | + | PHP errors do not provide backtraces, which can make it difficult to ascertain their underlying cause. Enabling backtraces for fatal errors will provide vital information to developers debugging production applications. |
Take, for example, a recursive infinite loop: | Take, for example, a recursive infinite loop: | ||
Line 50: | Line 51: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | Add configuration to enable backtraces for specific PHP error levels, defaulting to '' | ||
- | Generated backtraces must follow the existing setting for '' | + | Add a '' |
- | The pull request associated | + | When enabled, PHP will generate backtraces for errors |
- | ==== Why an error mask? ==== | + | '' |
- | The first version of this RFC proposed creating | + | ==== Why enable |
- | < | + | Backtraces that contain arguments will increment the refcount for those arguments, which means they will stay alive until the backtrace |
- | Second, PHP has plenty of functions (especially I/O functions) where | + | |
- | ignoring notices and warnings | + | |
- | back traces for errors your ignore. Keep in mind that error_get_last() data | + | |
- | is populated independently of whether errors are suppressed | + | |
- | Similarly, if your code promoted all warnings | + | By limiting this feature to only '' |
- | error handler, then you'll perform a duplicate backtrace calculation, | + | |
- | when the warning is originally through, and then again if you construct | + | |
- | exception. (This is less bad than other cases, because it's " | + | |
- | slow.) | + | |
- | Finally, even if we completely disregard the question of performance, | + | In addition, modern PHP applications tend to promote PHP warnings and notices to exceptions via '' |
- | traces are very noisy. You get one fatal error per request, but you might | + | |
- | easily get 1k warnings if something happens | + | |
- | traces, those 1k warnings | + | |
- | </ | + | |
- | + | ||
- | [[https:// | + | |
- | + | ||
- | < | + | |
- | To put my feedback into more actionable form: Rather than adding an ini | + | |
- | setting that enables error backtraces for all diagnostics, I'd make it a | + | |
- | mask of error types for which a backtrace | + | |
- | it to fatal errors only. So error_reporting=E_ALL, | + | |
- | error_backtrace=E_ERROR|E_CORE_ERROR|E_COMPILE_ERROR|E_USER_ERROR|E_RECOVERABLE_ERROR|E_PARSE. | + | |
- | It might be handy to expose the internal E_FATAL_ERRORS constant we have | + | |
- | for that. | + | |
- | + | ||
- | I think this should give a very sensible default behavior, and people who | + | |
- | want to capture backtraces for all errors still have an option to do so. | + | |
- | </ | + | |
- | + | ||
- | In short, I agree with this suggestion. Defaulting to '' | + | |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | * If the proposal | + | * If the sub-vote |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 107: | Line 78: | ||
==== To SAPIs ==== | ==== To SAPIs ==== | ||
- | As currently implemented, | + | There will be a new Zend global, '' |
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
Line 119: | Line 90: | ||
==== New Constants ==== | ==== New Constants ==== | ||
- | * '' | + | None. |
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | '' | + | '' |
* php.ini-development: | * php.ini-development: | ||
Line 132: | Line 103: | ||
This vote requires a ⅔ majority: | This vote requires a ⅔ majority: | ||
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
Line 139: | Line 110: | ||
---- | ---- | ||
- | This vote will require a simple majority. | + | This vote will require a simple majority: |
- | <doodle title=" | + | <doodle title=" |
- | * 'E_FATAL_ERRORS' | + | * ' |
+ | * ' | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | This vote determines if we need to update all '' | ||
+ | |||
+ | <doodle title=" | ||
+ | * '1' | ||
* ' | * ' | ||
</ | </ | ||
Line 158: | Line 138: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
+ | |||
+ | * Modifying the '' | ||
+ | * Storing backtraces as a string. This would solve the lifetime issue, but it would limit both applications and extensions from choosing their own desired format for the exception, e.g. they would be unable to JSON-format the exception if they desired. | ||
rfc/error_backtraces_v2.1733503332.txt.gz · Last modified: 2024/12/06 16:42 by enorris