Re: Use of 'self' in static function in subclass

From: Date: Tue, 01 Jun 2004 13:43:02 +0000
Subject: Re: Use of 'self' in static function in subclass
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-10202@lists.php.net to get a copy of this message
Bert Slagter wrote:
Hi All, I have a class and a subclass, both with a static method: <?php class Foo {
    static function Bar()
    {
        self::Baz();
    }
} class Foo2 extends Foo {
    static function Baz()
    {
        echo 'Baz';
    }
} Foo2::Bar(); ?> In this case I expect to find 'Baz' on my screen, but I get the following: "Fatal error: Call to undefined method Foo::baz() in d:\htdocs_php5\ProBase2\TRUNK\probase\libsys\test5.php on line 7". This is in PHP5 RC2. Somehow this behaviour seems logical, on the other hand I don't think it's desired. I think that 'self' should point to the current class, even if the static method resides in a parent class.
Yeah, this probably should change to be consistent. I've been living fine with the current behavior, but considering self::*() will automatically invoke the parent class' method if none is defined in current class, then it should probably also work the other way around. My .02, Hans

« previous php.internals (#10202) next »