把   $b1 = new b();改成 $this->b1 = new b();

解决方案 »

  1.   

    试试吧,我以前老犯这种错误windows2000下通过
      

  2.   

    语法错:
    class c{
        var $b1;
        function c(){
            $this->b1 = new b();
        }
    }
    class b{
        function hello()
        {
            echo "hello";
        }
    }
    $c1=new c();
    $c1->b1->hello();  //方案一 out hello
    $bb=$c1->b1;         //方案二 out hello
    $bb->hello();
      

  3.   

    不好意思,的确是应该写成$this->b1= new b();
    不过这样一来,问题更麻烦了,我是在pear里碰到这个问题的,运行的时候系统说pear源代码有错,也是调用了非对象的方式,可是,我看这个package的版本是稳定的,应该不会有这个问题吧!有兴趣的朋友可以看看Config这个包里面的PHPArray.php这个文件,我还是没有搞定
      

  4.   

    你可以把两个类的定义次序对调一下
    引用前先定义,php5也是这么要求的
      

  5.   

    div版
    http://snaps.php.net/
      

  6.   

    来来来,我如果想
    class c{
        var $b1;
        function c(){
              var $str='52mm';
            $this->b1 = new b();
              
        }
    }
    class b{
             
        function hello()
        {
            echo "hello";
             echo '?'; //我想在这里使用类b的成员$str,怎么写?
        }
    }
    $c1=new c();
    $c1->b1->hello();
    你们的方案是对的这个不容怀疑,帮我解决这个问题好吗?
      

  7.   

    class c{
        var $b1;
        var $str='52mm';
        function c(){
              
            $this->b1 = new b();
              
        }
    }
    class b{
             
        function hello()
        {
            echo "hello";
             echo $this->str; //我想在这里使用类b的成员$str,怎么写?
        }
    }