Detect Calling Class?
Posted: Tue Feb 21, 2006 12:08 am
I want to detect what class is calling a static function in another class... is that possible?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
function cool ( ) {
return $cashMoney > 300;
}
function isFeyd ( ) {
if ( $_SESSION['user'] == "Feyd" )
return true;
}That sounds like you are trying to do something that should probably be handled in a better way.Todd_Z wrote:I want to detect what class is calling a static function in another class... is that possible?
In PHP5 you could use __call() to intercept the method calls and run any code you wanted before running the requested code.Todd_Z wrote:Is there anyway to call a certain function before a function of a class is called?
Bear in mind that if the method you're calling a method which actually exists __call() will be ignored so write a routine that makes internal calls to private methods with systematically similiar names. i.e:arborint wrote:That sounds like you are trying to do something that should probably be handled in a better way.Todd_Z wrote:I want to detect what class is calling a static function in another class... is that possible?
In PHP5 you could use __call() to intercept the method calls and run any code you wanted before running the requested code.Todd_Z wrote:Is there anyway to call a certain function before a function of a class is called?
Code: Select all
private function _getFoo()
{
//
}Yes. Unfortunately __call(), __get() and __set() are error handlers and not real runtime overloading. But you can fake if you control the naming.d11wtq wrote:Bear in mind that if the method you're calling a method which actually exists __call() will be ignored so write a routine that makes internal calls to private methods with systematically similiar names.