禁止使用父类方法,使用关键字 final 

Class Notify

{

 protected $color = 'red';

 protected $credit = 10;

public final function message()

{

  return '<span style="color:'.$this->color.'">发送通知消息,奖励'.$this->credit().'个积分</span>';

}

}

 

Class User extends Notify

{

 protected $credit = 20;

//重写父亲方法需要更高方法名称,父类方法message已经被禁止重写

public function toUserMessage ()

{

return "重写父类方法!";

}

}

posted on 2020-04-14 14:41  易博奕-YBYsuccess  阅读(197)  评论(0)    收藏  举报