Proposal: Add debug_backtrace_depth(int $limit=0): int#6653
Closed
TysonAndre wants to merge 1 commit into
php:masterphp/php-src:masterfrom
TysonAndre:debug_backtrace_depthTysonAndre/php-src:debug_backtrace_depthCopy head branch name to clipboard
Closed
Proposal: Add debug_backtrace_depth(int $limit=0): int#6653TysonAndre wants to merge 1 commit intophp:masterphp/php-src:masterfrom TysonAndre:debug_backtrace_depthTysonAndre/php-src:debug_backtrace_depthCopy head branch name to clipboard
TysonAndre wants to merge 1 commit into
php:masterphp/php-src:masterfrom
TysonAndre:debug_backtrace_depthTysonAndre/php-src:debug_backtrace_depthCopy head branch name to clipboard
Conversation
Member
|
It might be reasonable to propose this on internals, if not already done. Also, please fix the merge conflicts. :) |
This can be polyfilled with
`min($limit, count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)))`.
- For debug_backtrace, the limit is to the number of frames scanned,
not the size of the returned array.
- For debug_backtrace_depth, the limit is on the returned depth)
It's faster just to not read the filenames, lines, create temporary arrays, etc.
This can be useful if you are checking for infinite recursion
to investigate a bug in an application.
E.g. `return debug_backtrace_depth(1000) >= 1000` would check
if php is more than 1000 stack frames of debug_backtrace deep.
This may have other uses, such as more efficiently
computing an indentation level in logging statements.
```
Processing Node A
Processing Node B
Processing Leaf C
Processing Leaf D
```
Note that php stack frames are a linked list - the amount of time to compute the
depth is proportional to the depth, and some frames do not show up in backtraces.
This PHP stack is separate from the C stack.
17df31b to
6bf14b6
Compare
|
There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This can be polyfilled with
min($limit, count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))).or less accurately as
count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $limit))not the size of the returned array.
It's faster just to not read the filenames, lines, create temporary arrays, etc.
This can be useful if you are checking for infinite recursion
to investigate a bug in an application.
E.g.
return debug_backtrace_depth(1000) >= 1000would checkif php is more than 1000 stack frames of debug_backtrace deep.
This may have other uses, such as more efficiently
computing an indentation level in temporary debug logging statements.
Note that php stack frames are a linked list - the amount of time to compute the
depth is proportional to the depth, and some frames do not show up in backtraces.
This PHP stack is separate from the C stack.
RFC: https://wiki.php.net/rfc/debug_backtrace_depth