Printing the calling file in a function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dhinge
Forum Newbie
Posts: 12
Joined: Mon Jan 08, 2007 1:56 pm

Printing the calling file in a function

Post 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?
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Printing the calling file in a function

Post by DigitalMind »

Code: Select all

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

f('Error', __FILE__);
User avatar
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

Post by John Cartwright »

debug_backtrace()may also be of use.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Printing the calling file in a function

Post by twinedev »

Also debug_print_backtrace()

-Greg
Post Reply