They're not the same thing.
class A {
protected function foo() {
return "a";
}
}
class B extends A {
protected function foo() {
return parent::foo() . "b";
}
public function bar() {
return $this->foo();
}
}
$b = new B();
var_dump($b->bar()); // "ab"
If instead you had:
class B extends A {
...
public function bar() {
return parent::foo();
}
}
var_dump($b->bar()); // just "a"
The foo
function of B
adds something to the foo
function of A
. This is a common pattern.
Whether calling parent::foo
in bar
is good or not depends on your design choices, I personally think it's a little iffy. Calling parent::foo
in foo
is fine by the way.