Thank you all for explaining.

This helps a lot!

Marc


On 09.03.20 10:27, Rowan Tommins wrote:
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,

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to