Re: Inheritance and a class function: on what class was it called?
| From: | Debbie Dyer | Date: | Thu, 03 Oct 2002 09:27:24 +0000 |
| Subject: | Re: Inheritance and a class function: on what class was it called? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118718@lists.php.net to get a copy of this message | ||
I have just double checked my facts and in both Java and C++ you cannot
access members of an ordinary class without first instantiating the class.
In both cases the only way you can do so is if that class contains a member
specifically declared as being special ie a class member as opposed to an
instance member & specifically declared to be static.
PHP on the other hand will let you access any functions of any class without
instantiation.
Maybe this is because, as I said before, PHP has no concept of the different
class/var/method types usually associated with classes. This is all very
different to what I know and does (is) causing confusion.
Debbie
----- Original Message -----
From: "Debbie Dyer" <debbie.dyer@c-u-online.co.uk>
To: "Rasmus Lerdorf" <rasmus@php.net>
Cc: <php-general@lists.php.net>
Sent: Wednesday, October 02, 2002 11:41 PM
Subject: Re: [PHP] Inheritance and a class function: on what class was it
called?
> Without them being defined in some special way?
>
> I am very surprised that after 7 years of OOP I dont know that but I will
> check it out tomorrow.
>
> Debbie
>
> ----- 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 11: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
> > >
> > > ----- Original Message -----
> > > From: "Rasmus Lerdorf" <rasmus@php.net>
> > > To: "Debbie Dyer" <debbie.dyer@c-u-online.co.uk>
> > > Cc: "Nick Eby" <nick_eby@bonzidev.com>;
> > > <php-general@lists.php.net>
> > > Sent: Wednesday, October 02, 2002 3:08 PM
> > > Subject: Re: [PHP] Inheritance and a class function: on what class was
> it
> > > called?
> > >
> > >
> > > > > The mistake is mine not yours. I know about the :: operator I use
it
> all
> > > the
> > > > > 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
> > > it
> > > > > because in all other languages I know trying to use an ordinary
> class
> > > before
> > > > > instantiation will just result in a null pointer error or the
> equivalent
> > > of
> > > > > one.
> > > > >
> > > > > PHP OOP is different I know, one big example is that there is no
> > > provision
> > > > > for data encapsulation - one of the main objectives of OOP,
neither
> can
> > > you
> > > > > differentiate between types of classes/methods (which is probably
> what
> > > is
> > > > > 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 (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>