Page 1 of 1

Print which class is calling a function

Posted: Wed Feb 24, 2010 10:32 am
by dhinge
I want to print the class calling a function in another class, for instance:

class Function_Class {
function callFunction() {
echo "The calling class is X";
}
}
class Calling_Class {
$functionClass = new Function_Class();

$functionClass->callFunction();
}

I want callFunction() to print the class calling it without having to pass $this or something like that. Is this possible?

Re: Print which class is calling a function

Posted: Wed Feb 24, 2010 10:55 am
by requinix
Yes, but you should have a really good reason for it.

So why do you want to do this?

Re: Print which class is calling a function

Posted: Wed Feb 24, 2010 10:57 am
by superdezign
I believe that this technique is known as "tracing." However, this is normally done for debugging, and debugging only.

Re: Print which class is calling a function

Posted: Wed Feb 24, 2010 1:59 pm
by McInfo
PHP Manual: debug_backtrace()

Edit: This post was recovered from search engine cache.