kickassamd Posted January 7, 2009 Share Posted January 7, 2009 <?php class aClassName { public function register($varName, $varValue) { // In here i would like to get the classes name that called this function. } } class thisWillCallaClassName { public function blah() { // I would like to call aClassName->register() from here and set this classes name automatically with no extra parameters to register } } ?> Is it possible to have a class that when called from within another class can get the classes name that is calling a function within. IE class people class bob -> calls a method in the people class, and the people class knows it was the class bob who is talking to it. Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/ Share on other sites More sharing options...
rhodesa Posted January 7, 2009 Share Posted January 7, 2009 not really...you can loop through debug_backtrace(), but that isn't recommended. can you pass the classname or $this as an argument to the register method? if you pass $this, the register method can use get_class() to see what the class is Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/#findComment-731933 Share on other sites More sharing options...
zeeli Posted January 7, 2009 Share Posted January 7, 2009 I'm not sure but are you looking for __CLASS__? Regards, zEeli Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/#findComment-731937 Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 I'm not sure but are you looking for __CLASS__? Regards, zEeli no, the OP wants the class name of the object A, which is calling object B's method. Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/#findComment-732206 Share on other sites More sharing options...
RussellReal Posted January 8, 2009 Share Posted January 8, 2009 get_class_name ? Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/#findComment-732267 Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 get_class_name ? it's get_class() and i already mentioned it above Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/#findComment-732370 Share on other sites More sharing options...
RussellReal Posted January 8, 2009 Share Posted January 8, 2009 oh haha Quote Link to comment https://forums.phpfreaks.com/topic/139897-oop-calling-class-name-question/#findComment-732502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.