faqts : Computers : Programming : Languages : PHP : kms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 20 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Is there a PHP function similar to Perl's "caller" which will return subroutine context?

Oct 23rd, 2003 13:42
Wouter van Vliet, Ryan, http://nl.php.net/manual/en/function.debug-backtrace.php


Yes. For a complete traceback of all places your script were before it 
arrived at the place you want to know where you were simply call 
debug_backtrace();

It will return a multidimensional array containing the function, line, 
file, class, type and args (where appropriate).

So, if you want to know from where your function (or subroutine) is 
called you'll need the second (index 1) item in the array. The first 
(index 0) contains information about the function from where 
debug_backtrace() is called.

Note: requires PHP 4.3.0 or higher