Re: Inheritance and a class function: on what class was it called?

From: Date: Wed, 02 Oct 2002 18:24:59 +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-118630@lists.php.net to get a copy of this message
not quite... the case I'm interested in is this, given your example: print C::foo(); which would print nothing, unfortunately, since when the function is called using the :: operator there is no $this variable. basically what I'm looking for is a replacement for get_class($this) when the function is called using :: thanks /nick "Debbie Dyer" <debbie.dyer@c-u-online.co.uk> wrote in message news:054c01c26a3f$34f6d230$de093c3e@homepc... > I think I know what you mean. You could get it to return the name of the > class. > > eg. > > class A { > function foo () { > return get_class($this); > } > } > class B extends A { > } > class C extends A { > } > > $a = new A(); > $b = new B(); > $c = new C(); > print $a->foo(); > print $b->foo(); > print $c->foo(); > > Is this what you mean? > > Debbie > > ----- Original Message ----- > From: "Nick Eby" <nick_eby@bonzidev.com> > To: <php-general@lists.php.net> > Sent: Wednesday, October 02, 2002 6:29 PM > Subject: [PHP] Inheritance and a class function: on what class was it > called? > > > > Assume you've got some class that has one or more classes inherited from > it. > > The parent class has a function that is normally called using the :: > > operator (a class function). Assume also that the class function is never > > called from an object function. Is it possible to find if the class > > function was called on the parent class, or on the child class? > > > > example: > > Class A has a function foo(), callable by A::foo(). Class B extends A. If > > outside code makes the call B::foo(), can you tell from within foo() that > > the function was called on B and not A? > > > > I think this is impossible but I want to confirm that suspicion. It's > > important that the call B::foo() isn't made from inside any object > function, > > so that there's no context for the $this variable; the get_class() > function > > isn't applicable. > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > >

« previous php.general (#118630) next »