class A {
    var $ref;
    var $name;
    function A($name) {
        $this->name = $name;
    }    function getName() {
        echo ("my name is ".$this->name);
       //return "my name is ".$this->name;
    }    function example() {
        //$this->ref = &getName();  //错误的行
        $this->getName();
    }    function getRef() {
    return $this->example();
    }
}$a = new A('John');
$a->getName();
$a->getRef();
=========================
在一个对象的方法中,$this 永远是调用它的对象的引用

解决方案 »

  1.   

    function &example() {
            
            $this->ref=$this->getName();
        }
      

  2.   

    class A {
        var $ref;
        var $name;
        function A($name) {
            $this->name = $name;
        }    function &getName() {
            echo ("my name is ".$this->name);
        }    function &example() {
            $this->ref=&$this->getName();
        }    function getRef(&$arg) {
            $this->ref = &$this->example();
            //echo $this->ref;
        }
    }$a = & new A('John');
    $a->getName();
    $a->getRef($a->getName());不知道这样符不符合你的要求。