Page 1 of 1

Is there a way to get name of class which calls a method?

Posted: Wed May 23, 2007 4:05 am
by mcccy005
Is there a way to get the name of a particular class/object/file which has called a particular method from within the method itself??

Basically I want only a particular class to be able to call a particular method of another class without extending from one to the other etc.

Posted: Wed May 23, 2007 4:23 am
by Kieran Huggins
I think your best bet would be to send it as a method argument:

Code: Select all

$someClass::methodName('arg1',__CLASS__);

Re: Is there a way to get name of class which calls a method

Posted: Wed May 23, 2007 4:48 am
by stereofrog
mcccy005 wrote:Is there a way to get the name of a particular class/object/file which has called a particular method from within the method itself??

Basically I want only a particular class to be able to call a particular method of another class without extending from one to the other etc.
You can use debug_backtrace, but the whole thing seems quite odd to me. Care to explain why you think you need this?

Posted: Wed May 23, 2007 4:53 am
by mcccy005
Main reason is that the method I'm using allows certain fields and corresponding values to be deleted from a generated sql query. I only want access to this particular method from one particular class.
Thats primarily why.

I did read something about that backtrace in other posts whilst searching but everyone said it was a bit dodgy so figured I'd try my luck with this post.

Posted: Wed May 23, 2007 6:58 am
by feyd