NavigationUser login |
How method scope affects functionalityIts not always obvious which method gets called when overloading methods with different access controls and calling them from the parent class. Consider:
<?php
class C1 {
public function __construct() {
$this->go();
}
private function go() {
echo "In the C1::go()\n";
}
}
class C2 extends C1 {
public function __construct() {
parent::__construct();
}
protected function go() {
echo "In the C2::go()\n";
}
}
$c=new C2();
Now consider:
class C1 {
public function __construct() {
$this->go();
}
protected function go() {
echo "In the C1::go()\n";
}
}
class C2 extends C1 {
public function __construct() {
parent::__construct();
}
protected function go() {
echo "In the C2::go()\n";
}
}
$c=new C2();
|
Recent blog posts
|