Page 1 of 1

Detect Calling Class?

Posted: Tue Feb 21, 2006 12:08 am
by Todd_Z
I want to detect what class is calling a static function in another class... is that possible?

Posted: Tue Feb 21, 2006 12:12 am
by feyd

Posted: Tue Feb 21, 2006 12:23 am
by Todd_Z
I bow to your H4X

Posted: Tue Feb 21, 2006 12:31 am
by Todd_Z
Continuation of that....

Is there anyway to call a certain function before a function of a class is called?

For example:

Code: Select all

function cool ( ) {
  return $cashMoney > 300;
}

function isFeyd ( ) {
  if ( $_SESSION['user'] == "Feyd" )
    return true;
}
basically, I want to call function cool, and it would call isFeyd() before starting the main body of the function.

Posted: Tue Feb 21, 2006 12:36 am
by feyd
outside of the runkit extension and PHP 5, I don't believe so.

Posted: Tue Feb 21, 2006 12:48 am
by Christopher
Todd_Z wrote:I want to detect what class is calling a static function in another class... is that possible?
That sounds like you are trying to do something that should probably be handled in a better way.
Todd_Z wrote:Is there anyway to call a certain function before a function of a class is called?
In PHP5 you could use __call() to intercept the method calls and run any code you wanted before running the requested code.

Posted: Tue Feb 21, 2006 2:56 am
by Chris Corbyn
arborint wrote:
Todd_Z wrote:I want to detect what class is calling a static function in another class... is that possible?
That sounds like you are trying to do something that should probably be handled in a better way.
Todd_Z wrote:Is there anyway to call a certain function before a function of a class is called?
In PHP5 you could use __call() to intercept the method calls and run any code you wanted before running the requested code.
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:

Code: Select all

private function _getFoo()
{
    //
}
Where __call() executes the method from inside the class if simply getFoo() is called ;)

Posted: Tue Feb 21, 2006 2:59 am
by Christopher
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.
Yes. Unfortunately __call(), __get() and __set() are error handlers and not real runtime overloading. But you can fake if you control the naming.