Forum Moderators: coopster

Message Too Old, No Replies

Function Caller ID

Is there a way to find out where the function call came from?

         

DrDoc

7:51 am on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, take OOP and classes (and such), or a simple function in some file included by several scripts. If I want the script to throw an error (or, log an error), can I somehow find out (or backtrack) where the function call came from, or which script/line/function in turn called/included me? This especially becomes of interest for classes and files which handle database calls for an entire site.

coopster

7:01 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You mean something like the Magic constants [php.net]?

DrDoc

10:51 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, because I want it to return parent data, not from inside the included file/class.

coopster

6:14 pm on Feb 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not aware off-hand of any PHP functions or constants that contain this type of information. Typically what I will do is monitor for the error and handle accordingly.

So, let's say there are 3 different query statements being processed and I want to know which is failing. If I monitor for the error in the class method itself, I am not going to find out much unless I dump that particular statement as part of the error. Then I can go back in the code and figure out which statement it is (usually).

However, if I were to process the statement and set an overall class error and monitor for that error upon return of the invoked method, I can now tell which file, line, etc the error was trapped at. Very similar to what you see in PEAR's error-monitoring routines.