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?
Printing the calling file in a function
Moderator: General Moderators
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: Printing the calling file in a function
Code: Select all
function f($error, $file) {
echo "$file: $error\n";;
}
f('Error', __FILE__);
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Printing the calling file in a function
debug_backtrace()may also be of use.
Re: Printing the calling file in a function
Also debug_print_backtrace()
-Greg
-Greg