protected函数中含有private属性,此类被继承后,此属性是否有效

来源:互联网 发布:axure rp mac 破解版 编辑:程序博客网 时间:2024/05/15 23:45
答案是肯定的,以下面代码为例:
 <?php  class A                                          {      private $var;      protected function fun()      {          $this->var = 'Hello var!';          echo $this->var;      }     }     class B extends A  {      public function fun0()      {          $this->fun();      }     }     $b=new B();  $b->fun0(); ?>
其中,var为class A中私有变量,被protected型fun函数调用。当class A被class B继承,class B并不能继承属性var,但是class B调用fun函数时,属性var仍然是有效的。

浏览器中显示结果如下:

Hello var!

原创粉丝点击