我有类名Animal,它由两个方法组成,比如...
Class Animal
{
protected function method1(){
//some code
}
protected function method2(){
//some code
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想创建两个扩展类Animal的子类.一个是猫,另一个是狗,就像
Class Cat extends Animal
{
}
Run Code Online (Sandbox Code Playgroud)
和,
Class Dog extends Animal
{
}
Run Code Online (Sandbox Code Playgroud)
现在,我想要的是,子类Cat可以访问类Animal中定义的方法,但类Dog可以访问method1,而不是method2.如何在类Animal中设置访问修饰符,以便这种逻辑可以发生?
我在 Linux 上使用 Php Smarty。
我的 PHP 文件中有一行:
$phpsmart->display("pagetemplate.tpl");
Run Code Online (Sandbox Code Playgroud)
该行应该显示pagetemplate.tpl. 事实并非如此。