protected与private在构造函数选择执行时的差异[有点乱,请看实例]

<?php
class A{
function __construct(){
   $this->say();
   $this->hello();
  }
protected function say(){
 echo __CLASS__."[A]<br/>";
  }
private function hello(){
  echo "[a]hello<br/>";
  }
}

class B extends A{
function __construct(){
    parent::__construct();
    $this->say();
    $this->hello();
 }
 function say(){
 echo __CLASS__."[B]<br/>";
}
 function hello(){
  echo "[b]hello<br/>";
  }
}
$a=new B();
?>

output:

B[B]
[a]hello
B[B]
[b]hello

 

parent::__construct()执行时 say方法是子类的,而hello类是父类的,差异十分明显
posted @ 2013-06-11 21:59  H&K  阅读(252)  评论(0编辑  收藏  举报