当前位置: 代码迷 >> PHP >> .子内内部调父类属性或方法.解决思路
  详细解决方案

.子内内部调父类属性或方法.解决思路

热度:88   发布时间:2016-04-28 19:50:54.0
...子内内部调父类属性或方法...
class A{
     public $m=20;
     function test(){
             echo 1;
     }

}

class B extends A{

...子内内部调父类属性或方法...

}

B继承A,在B类部可以A::test(),parent::test()或者$this->test()这样三种形式调父类的方法,
不知道子类内部调父类属性的方式有几种,难道只有$this->m一种?
------解决方案--------------------
调用属性的话:如果是非static类型的,估计只能 $this->test 了。如果是static的可以 parent::test
  相关解决方案