PHP的extends继承关系

废话少说上代码:<?php 

Class Notify{

protected $color = "red"; //子类也可以继承属性
public function message(){ return '<span style="color:'.$this->color.'">发送通知消息</span>'; } } Class User extends Notify { public function register(){ return $this->message(); }
}

Class Comment extends Notify{

public function send()
{

return $this->message();

}

}

echo (new Comment)->send();

 

posted @ 2020-03-25 17:03  blog_zss小帅-博客猿  阅读(161)  评论(0编辑  收藏  举报