protected与private在构造函数选则执行时的差异[有点乱,请看实例]
<?phpclass A{function __construct(){ $this->say(); $this->hello(); }protected function say(){ echo __CLASS__."[A] "; }private function hello(){ echo "[a]hello "; } }class B extends A{function __construct(){ parent::__construct(); $this->say(); $this->hello(); } function say(){ echo __CLASS__."[B] "; } function hello(){ echo "[b]hello "; } }$a=new B();?>
output:
B[B]
[a]hello
B[B]
[b]hello
parent::__construct()执行时 say方法是子类的,而hello类是父类的,差异十分明显