Re: [RFC Proposal] Allow methods to 'become' static

From: Date: Mon, 15 Mar 2021 14:49:02 +0000
Subject: Re: [RFC Proposal] Allow methods to 'become' static
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-113539@lists.php.net to get a copy of this message
On 15/03/2021 13:16, Matthew Brown wrote:
On Sun, 14 Mar 2021 at 18:09, Rowan Tommins <rowan.collins@gmail.com <mailto:rowan.collins@gmail.com>> wrote:
    Are you saying that having the parent::getSomeInt() call fail
    would be
    problematic?
 Yes, that's where this becomes unsound – you can call the child method statically, but the parent call assumes a dynamic instance.
This isn't really to do with changing the signature of the method though; it will give you exactly the same error as if you gave the static and non-static methods different names: class A {
    public int $someInt = 0;
    public function getSomeInt() : int {
        return $this->someInt;
    }
} class B extends A {
    public static function getSomeIntStatically() : int {
        return parent::getSomeInt(); // This call is invalid; this is currently only reported when the method is run
    }
} Regards, -- Rowan Tommins [IMSoP]

Thread (8 messages)

« previous php.internals (#113539) next »