How do I find out the filename of the script that called my function?
For example,
function sthing() {
echo __FILE__; // echoes myself
echo __CALLER_FILE__; // echoes the file that called me
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A solution might be to use the
debug_backtracefunction : in the backtrace, that kind of information should be present.Or, as Gordon pointed out in a comment, you can also use
debug_print_backtraceif you just want to output that information and not work with it.For instance, with
temp.phpcontaining this :and with
temp-2.phpcontaining this :Calling
temp.php(i.e. the first script)from my browser gets me this output :In there, I have the “
temp.php” filename — which is the one in which the function has been called.Of course, you’ll have to test a bit more (especially in situations where the function is not in the “first level” included file, but in a file included by another one — not sure
debug_backtracewill help much, there…) ; but this might help you get a first idea…