Skip to content

There's __FILE__, __LINE__, __METHOD__, __CLASS__ and slow debug_backtrace() call. Why not create __TRACE__ ? #18437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gzhegow1991 opened this issue Apr 26, 2025 · 5 comments

Comments

@gzhegow1991
Copy link

Description

I mean constant trace that equals first step of debug_backtrace() without arguments.

Before i compared exception creation with calling debug_backtrace(NO_ARGS, limit = 1) and creating exception was FASTER.

But using constants like FILE and LINE is faster 4 times that creating the exception. Why not create TRACE constant to give possibility to require argument filled with this TRACE ?

@iluuu1994
Copy link
Member

Because it's not constant. It changes depending on where the function is called from. https://3v4l.org/mmYE5

@gzhegow1991
Copy link
Author

Mdahaha. "We are not creating the function because the requester named it incorrectly"

@iluuu1994
Copy link
Member

Sigh. Have you even tried to understand my comment? Constants don't change value between execution. __FILE__ always refers to the same string within a function. __TRACE__ would not, it would change depending on where the function is called from. Hence, it cannot be constant. It must be dynamic, and whether you write __TRACE__ or debug_backtrace() will not change that fact. It needs to be constructed at runtime.

@iluuu1994 iluuu1994 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2025
@gzhegow1991
Copy link
Author

gzhegow1991 commented Apr 27, 2025

FILE is the same as file
LINE is the same as line
METHOD is the same as method

TRACE in my opinion is just array with all described above

[
 'file' => __FILE__,
 'line' => __LINE__,
 'class' => __CLASS__, // or null (empty string?)
 'function' => __FUNCTION__, // or null (empty string?)
 'type' => '->', // or `::` or null (empty string?) // dynamic too? depends on the call? or depends on the `static` word in method signature?
 'args' => func_get_args(), // or empty array or just dont add this key at all cause of dynamic
]

Exactly if you want to store all inside error object with simple word __TRACE__

I mean only last line, i understand that all trace items depends on the position you call the function - but last line is not. I mean __TRACE__ as last line only.

Also good feature would be
__LAST_FILE__
__LAST_LINE__

or something mean previous values

that can be used by dump functions that should know only the place where they're called (usually i retrieve it by debug_backtrace(no_args, 1) but maybe this is really NOT constant and cannot be declared on cUmpilation time as constants (the point you referenced)

@MorganLOCode
Copy link

So you're basically wanting something easier to write than ['file' => __FILE__, 'line' => __LINE__, 'class' => __CLASS__, 'function' => __FUNCTION__]. Information about the caller really cannot be collected at compilation time, so would have to be done at execution time. It looks like you're not interested in the rest of the backtrace (you've given a limit of 1), so that's all debug_backtrace would be collecting anyway. Whether arguments are provided or not is basically cosmetic, as that information is already part of the stack frame and the no_args choice is simply about whether to include it in the return value.

Unless you limit yourself to the associative array in the previous paragraph, I'm not seeing where the performance savings would be made. I'm also not seeing the what benefits of such a performance gain would be to what is a debugging tool that (a) shouldn't be getting executed that often in the first place, and (b) when it does would only be a prelude to much more time spent fixing the bug that it has revealed.

@php php locked and limited conversation to collaborators Apr 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants