I'm wondering what is the difference between using self:: and parent:: when a static child class is extending static parent class e.g.
class Parent {
public static function foo() {
echo 'foo';
}
}
class Child extends Parent {
public static function func() {
self::foo();
}
public static function func2() {
parent::foo();
}
}
Is there any difference between func() and func2() and if so then what is it ?
Thank you
Regards
overridden
foo() in the Child class, thenself::foo()
calls the child class version whileparent::foo()
calls the original parent version – Roerstatic::foo()
makes it even more fun :) – Roerfoo()
then it executes the parentfoo()
code.... there's a difference in the calls, but not in what is executed. Callingparent::foo()
will always execute the parent class foo() method, even if the child overrides it; calling self::foo() will execute the foo() override if it exists in self (ie the child), otherwise it will execute the parent foo() if no override exists – Roer