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 {}


thanks again

----- Original Message -----
From: "Rasmus Lerdorf" <[EMAIL PROTECTED]>
To: "Debbie Dyer" <[EMAIL PROTECTED]>
Sent: Wednesday, October 02, 2002 3:08 PM
Subject: Re: [PHP] Inheritance and a class function: on what class was it

> > The mistake is mine not yours. I know about the :: operator I use it all
> > time (but within classes parent::function() etc) - but I never realised
> > until now that PHP will let you use any class before instantiation (and
> > nearly all my PHP work uses classes). I have never even attempted to try
> > because in all other languages I know trying to use an ordinary class
> > instantiation will just result in a null pointer error or the equivalent
> > one.
> >
> > PHP OOP is different I know, one big example is that there is no
> > for data encapsulation - one of the main objectives of OOP, neither can
> > differentiate between types of classes/methods (which is probably what
> > causing the confusion).
> >
> > Now it seems it is even more different than I thought. All I can say is
> > mmhh.......
> Most OO languages allow static method calls.  C++, Java, Python, Ruby,
> etc.  PHP may have some OO differences, but this is not one of them.
> -Rasmus

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to