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. 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 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 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. 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 ? 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 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 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
Archived
This topic is now archived and is closed to further replies.