Page 1 of 1

Printing the calling file in a function

Posted: Tue Sep 28, 2010 4:49 pm
by dhinge
I have a function that writes to a log file, and I want to print the name of the calling file. For instance:

$output = $calling_file . ": $error";

so it looks like:

index.php: There was an error!

Even better would be a relative path like "/classes/GetData.php: There was an error!"

Any way to do either of these?

Re: Printing the calling file in a function

Posted: Tue Sep 28, 2010 5:00 pm
by DigitalMind

Code: Select all

function f($error, $file) {
    echo "$file: $error\n";;
}

f('Error', __FILE__);

Re: Printing the calling file in a function

Posted: Tue Sep 28, 2010 5:02 pm
by John Cartwright
debug_backtrace()may also be of use.

Re: Printing the calling file in a function

Posted: Tue Sep 28, 2010 7:27 pm
by twinedev
Also debug_print_backtrace()

-Greg