有没有办法在不覆盖整个方法的情况下覆盖扩展类方法的可见性?
class A
{
public function perform()
{
// Do a bunch of stuff that you don't want to override.
}
}
class B extends A
{
/*
* Change perform()'s viability from public
* to protected without re-coding the whole method.
*/
}
// You can not do this.
$b = new B();
$b->perform();
答案 0 :(得分:1)
您可以创建一个简单调用父方法的受保护方法:
class B extends A
{
protected function perform() {
parent::perform();
}
}