Re: [RFC Proposal] Allow methods to 'become' static
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)