Re: Bug Wrong resolution of "Late Static Binding" after self::method()

From: Date: Mon, 09 Mar 2020 09:27:34 +0000
Subject: Re: Bug Wrong resolution of "Late Static Binding" after self::method()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-108905@lists.php.net to get a copy of this message
On Mon, 9 Mar 2020 at 05:38, Marc <marc@mabe.berlin> wrote: > > Does it make sense? -> I have read "self::" all time as a shortcut for > "MyClass::" until I noticed this is not the case and I expect most PHP > devs would explain it this way. > > Is there a reason why self:: doesn't reset the internal "static" reference? > A reasonably intuitive parallel that occurred to me is that $this is also maintained through self:: calls (as long as they're not to a method declared static). So if you replace the static:: call in my previous example with a $this-> call, you get the same result: # https://3v4l.org/deRcD class A { function call() { self::method1(); } function method1() { $this->method2(); } function method2() { echo 'Base definition'; } } class B extends A { function method2() { echo 'Override'; } } (new B)->call(); # echoes 'Override' Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#108905) next »