*<Double post> I can't edit my previous note to elaborate on modifiers. Please excuse me.*
If both parent and child classes have a method with the same name defined, and it is called in parent's constructor, using `parent::__construct()` will call the method in the child.
<?php
class A {
public function __construct() {
$this->method();
}
public function method() {
echo 'A' . PHP_EOL;
}
}
class B extends A {
public function __construct() {
parent::__construct();
}
}
class C extends A {
public function __construct() {
parent::__construct();
}
public function method() {
echo 'C' . PHP_EOL;
}
}
$b = new B; $c = new C; ?>
In this example both A::method and C::method are public.
You may change A::method to protected, and C::method to protected or public and it will still work the same.
If however you set A::method as private, it doesn't matter whether C::method is private, protected or public. Both $b and $c will echo 'A'.