时间:2021-07-01 10:21:17 帮助过:23人阅读
salutation
");
$this->identify();
}
protected function identify()
{
print("I am Father.
");
}
};
class Son extends Father
{
protected $salutation = "Hey!"; //父类中的protected $salutation 被覆写
protected function identify() //父类中的protected identify() 被覆写
{
print("I am Son.
");
}
};
$obj = new Son();
$obj->getSalutation(); //输出Hey! I am Son.
?> salutation
");
$this->identify();
}
private function identify()
{
print("I am Father.
");
}
}
class Son extends Father
{
private $salutation = "Hey!";
private function identify()
{
print("I am Son.
");
}
}
$obj = new Son();
$obj->getSalutation(); //输出Hello there! I am Father.
?>name);
}
public function deleteUser($username) //删除用户
{
if(!$this->isAuthorized())
{
print("You are not authorized.
");
return(FALSE);
}
//delete the user
print("User deleted.
");
}
}
class AuthorizedUser extends User //认证用户
{
protected function isAuthorized() //覆写isAuthorized()
{
return(TRUE);
}
}
$user = new User;
$admin = new AuthorizedUser;
//not authorized
$user->deleteUser("Zeev");
//authorized
$admin->deleteUser("Zeev");
?> http://www.bkjia.com/PHPjc/532554.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532554.htmlTechArticle第九节--绑定 除了限制访问,访问方式也决定哪个方法将被子类调用或哪个属性将被子类访问. 函数调用与函数本身的关联,以及成员访问与变...