Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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#6653
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

@TysonAndre
Copy link
Copy Markdown
Contributor

@TysonAndre TysonAndre commented Jan 30, 2021

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))

  • 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 temporary debug 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.

RFC: https://wiki.php.net/rfc/debug_backtrace_depth

@cmb69
Copy link
Copy Markdown
Member

cmb69 commented Mar 10, 2021

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.
@TysonAndre TysonAndre force-pushed the debug_backtrace_depth branch from 17df31b to 6bf14b6 Compare March 13, 2021 16:21
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 5, 2022

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.