Re: Object Inheritance, get_class() and a static function call
| From: | Jochem Maas | Date: | Wed, 27 Jul 2005 13:09:09 +0000 |
| Subject: | Re: Object Inheritance, get_class() and a static function call | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-219413@lists.php.net to get a copy of this message | ||
axel wrote:
Hello Jochem, Axel lets start again. Okay. SO: explain, please, why and what you are trying to do (DETAILS!). don't dumb it down because that just makes the problem look moot. I need the classname to register variables in the session. It's complicated. There are a lot of inheritences. Please take a look at the code:will take a deeper look this evening ... but ...
class onObject { // ... } abstract class onAplObject extends onObject { protected static function registerVariable($key, $value) {try making the function defintion like this: protected function registerVariable($key, $value) { and then use: $theRealClassName = get_class($this); otherwise the simplest solution maybe to do: protected static function registerVariable($obj, $key, $value) { and then: $theRealClassName = get_class($obj); which is a little clumsy but will work!
$theRealClassName = ???;# $theRealClassName = get_class($this); # output is --> Undefined variable: this in ...# $theRealClassName = get_class(self); # output is --> Notice: Use of undefined constant self ...# $theRealClassName = __CLASS__; # => $theRealClassName=="onAplObject"# $theRealClassName = debug_backtrace()[1]['class']; # => $theRealClassName=="onDbTableEdit"# $theRealClassName = debug_backtrace()[0]['class']; # => $theRealClassName=="onAplObject"$_SESSION[$theRealClassName.'_'.$key]=$value;} } class onDbTableEdit extends onAplObject { public static function show() { self::registerVariable("listsort", "id"); } } class onUseradmin extends onDbTableEdit { // .... } onUseradmin::show(); Best regards Axel