感觉PHP中的类继承和对象引用总是有问题 ,不想其他的编程语言一样 我是从DELPHI中转过来的里面有的机制和PHP查的有点太~~~~  所以想想问问是不是我的想法错了还是PHP无法实现。

解决方案 »

  1.   

    <?php
    class a{
      function test1(){
       echo "hello";
      }
    }class b extends a{
      var $var_a;
      function b(){
       $this->var_a = new a();
      }}class c{
      var $var_b;
      function c(){
        $b = new b();
        $b->var_a->test1();//这样调用为什么会出错 
      }
    }
    $p = new c;?>
      

  2.   

    是我错了  引用正确的方法如下 :)
    <?php
    class a{
      function test1(){
       echo "你好";
      }
    }class b extends a{
      var $var_a;
      function b(){
       $this->var_a = new a();
      }}class c{
      var $var_b;
      function c(&$b){
      $this->var_b=$b;
      $this->var_b->test1();
      }
    }
    $s = new b;
    $p = new c(&$s);?>这样就可以使用一些机制去扩展类和对象了 :)  结贴