Re: Use of 'self' in static function in subclass
| From: | Jevon Wright | Date: | Wed, 02 Jun 2004 00:36:26 +0000 |
| Subject: | Re: Use of 'self' in static function in subclass | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10237@lists.php.net to get a copy of this message | ||
It's something I noticed, too. Consider this:
class A {
function a() { return $this::b(); }
function b() { return 1; }
}
class B extends A {
function b() { return 2; }
}
If I call
$b = new B();
echo $b->a();
No matter what combination of this, self, parent, ... - I could never get
B's property. I was led to believe that this is actually normal for OO
designs (is it? If so, ignore me). But it would be awesome if self or $this
(ONLY one of them, if they currently perform the same function) actually
referred to the top class - ie. B::b() in this case. Is this what this
suggestion would suggest?
Thanks,
Jevon
----- Original Message -----
From: "Adam Bregenzer" <adam@bregenzer.net>
To: "Hans Lellelid" <hans@velum.net>
Cc: "Ferdinand Beyer" <fb@fbeyer.com>; "Timm Friebe"
<thekid@thekid.de>;
<internals@lists.php.net>
Sent: Wednesday, June 02, 2004 12:26 PM
Subject: Re: [PHP-DEV] Use of 'self' in static function in subclass
> On Tue, 2004-06-01 at 19:53, Hans Lellelid wrote:
> > Yeah +1 on self:: binding at runtime. I can't really imagine a case
> > where you would want to refer to 'self' as the class that contains the
> > method *and not* the overridden method in invoked class (if it exists).
> > Binding this at runtime will introduce many new design possibilities
> > with static classes and will also make self:: consistent with $this->
> > behavior for objects.
>
> +1, I agree completely. I think it is critical to have a way to be able
> to have a static method call another static method in the same class
> that respects inheritance. If a developer wanted a call to not respect
> inheritance the class's name can be used instead of self with the same
> results (increased code maintenance should the class name change
> notwithstanding).
>
> --
> Adam Bregenzer
> adam@bregenzer.net
> http://adam.bregenzer.net/
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>