PHP - Do you know about debug_backtrace function?

Ricardo Heck
Dev Ticks
Published in
1 min readJul 27, 2017

You have probably come across a situation where you needed to figure out where the call of a method is coming from.
What many PHP developers do not know is an old function, which has been available since version 4, called debug_backtrace.

This function is responsible for returning an associative array with all the call backtrace to the function being executed at the moment.
By default, the returned array contains the complete backtrace, without limit. However, you can specify a limit though the arguments to control the number of stack frames returned.
Check the possible returned elements from the function:

You can check examples in the PHP documentation which I strongly recommend you to read.

Thanks for staying until here. See you in the next article.

--

--