Re: Inheritance and a class function: on what class was it called?
| From: | Nick Eby | Date: | Wed, 02 Oct 2002 22:49:49 +0000 |
| Subject: | Re: Inheritance and a class function: on what class was it called? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118673@lists.php.net to get a copy of this message | ||
which is what I suspected... thanks for confirming. and yes, the call is
disconnected from any class _instance_, but not from any class. as you said
before, PHP has some OO differences from java, etc, and this is one of
them... if you had static members, then methods called statically would have
to know on what class they were called. anyway thanks again
/nick
----- Original Message -----
From: "Rasmus Lerdorf" <rasmus@php.net>
To: "Nick Eby" <nick_eby@bonzidev.com>
Cc: "Debbie Dyer" <debbie.dyer@c-u-online.co.uk>;
<php-general@lists.php.net>
Sent: Wednesday, October 02, 2002 3:28 PM
Subject: Re: [PHP] Inheritance and a class function: on what class was it
called?
> Since static method calls are completely disconnected from any class
> instance asking which class the method call is from is rather meaningless,
> and no, I don't think there is any way to get that.
>
> -Rasmus
>
> On Wed, 2 Oct 2002, Nick Eby wrote:
>
> > PHP allows static method calls... But back to my original question...
> > inside a method that has been called statically, can I determine for
what
> > class the method was called? Again, obviously the question is only
> > applicable if there is some inheritance involved, and the child class
does
> > not declare the method in question. Below is my original example
spelled
> > out in code... the call to get_class is not valid since there won't be a
> > $this variable in the context of the static method... Can I replace it
with
> > something that will cause it to echo "B"?
> >
> > Class A {
> > function staticFunc() { echo get_class($this); }
> > }
> >
> > Class B extends A {}
> >
> > B::staticFunc();
> >
> > thanks again
> > /nick
> >