function backtrace possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jpschroeder
Forum Newbie
Posts: 4
Joined: Tue May 27, 2008 9:54 am

function backtrace possible?

Post by jpschroeder »

Hello,

Is it possible to traceback recent functions? For example in lets assume that I run function A, B, then C. In function C is there a way to find out that function A and B werre previously run without setting any variables during their execution? I'm familiar with __FUNCTION__ but that only gives the current function (I believe).

There is also debug_backtrace() but that seems to just list the magic variables, thus only listing the current function.

Thanks for any help!
jpschroeder
Forum Newbie
Posts: 4
Joined: Tue May 27, 2008 9:54 am

Re: function backtrace possible?

Post by jpschroeder »

For anyone interested...

I somewhat solved the issue with debug_traceback(), but its quite rough. You receive an array full of information on previous functions that have been run.

To access previous functions you would use this format:

Code: Select all

 
$function = degub_backtrace();
$function[0]['function']     // The current function
$function[1]['function']     // Most recently executed function before this one
$function[2]['function']     // Second most recently executed function before this one etc...
 
If anyone has better information that would be awesome!
Post Reply