Detect Calling Class?
Moderator: General Moderators
Detect Calling Class?
I want to detect what class is calling a static function in another class... is that possible?
Continuation of that....
Is there anyway to call a certain function before a function of a class is called?
For example:
basically, I want to call function cool, and it would call isFeyd() before starting the main body of the function.
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;
}- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
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?
(#10850)
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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()
{
//
}- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
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.
(#10850)