php函数的引用返回

来源:互联网 发布:苹果手机哪里开4g网络 编辑:程序博客网 时间:2024/05/17 08:32
//This is the way how we use pointer to access variable inside the class.<?phpclass talker{    private $data = 'Hi';    public function & get(){        return $this->data;    }    public function out(){        echo $this->data;    }   }$aa = new talker();$d = &$aa->get();$aa->out();$d = 'How';$aa->out();$d = 'Are';$aa->out();$d = 'You';$aa->out();?>//the output is "HiHowAreYou"

<?phpclass a {var $abc = "ABC";}$b = new a;$c = $b;echo $b->abc; // 这里输出ABCecho $c->abc; // 这里输出ABC$b->abc="DEF";echo $c->abc; // 这里输出DEF?>

new对象之后默认返回引用,所以$c是$b的一个引用
0 0
原创粉丝点击