Re: Inheritance and a class function: on what class was it called?
| From: | Debbie Dyer | Date: | Wed, 02 Oct 2002 18:12:00 +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-118627@lists.php.net to get a copy of this message | ||
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
>
>