1 class a{ 2 static public $b = 1; 3 private $d = 5; 4 //public $d = 5; 5 public function aa(){ 6 echo self::$b; 7 } 8 9 public function cc(){ 10 echo static::$b; 11 } 12 13 public function dd(){ 14 echo $this->d; 15 $this->rr(); 16 } 17 } 18 19 class b extends a{ 20 static public $b = 2; 21 //private $d = 6; 22 public $d = 6; 23 public function bb(){ 24 echo self::$b; 25 } 26 27 public function rr(){ 28 echo 8; 29 } 30 } 31 32 $b = new b(); 33 $b->bb(); //2 34 $b->aa(); //1 35 $b->cc(); //2 36 $b->dd(); //以子类为准,但是私有的父类不能访问,但是如果父类是私有的,则为父类为准,不管子类是否是私有
我理解为存在继承关系,$this为父类子类的实例共同体,访问的变量及方法的优先级为 变量/方法 的公开程度 》 继承关系(子类优先)