Proposal: Add debug_backtrace_depth(int $limit=0): int #6653
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) >= 1000
would 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