参考 [英] References
问题描述
我想我不明白引用如何在php中工作;
下面以类成员函数为例;
function& getRow()
{
返回odbc_fetch_array($ this-> _det);
}
我希望我应该最终没有任何东西,因为没有什么可以参考。
如果我指定如下参考;
$ var = getRow()
然后回显结果;
echo $ var [''name''];
echo $ var [''address'' ];
它一切正常,这让我感到惊讶。
在其他语言中我有更多的经验,这会引发错误,或
留下你没有任何参考,但在PHP 5中,我可以使用这个
变量没有问题。
如果有的话,php会复制结果没有var实际传递
参考?
我看不出它是怎么回事。
一个解释非常感谢。
TIA,
Vince
I guess I don''t understand how references work in php;
Calling a class member function below as an example;
function &getRow()
{
return odbc_fetch_array($this->_det);
}
I would expect that I should end up with nothing as there is nothing to
actualy reference.
If I assign the reference as below;
$var = getRow()
and then echo the result;
echo $var[''name''];
echo $var[''address''];
it all works fine, which surprises me somewhat.
In other languages I have more experience with this would throw an error, or
leave you with a reference to nothing, however in php 5 I can use this
variable hereon without a problem.
Does php make a copy of the result if there is no var to actualy pass a
reference to?
I can''t see how it isn''t.
An explaination of this would be very appreciated.
TIA,
Vince
推荐答案
this- > _det);
}
我希望我最终没有任何东西,因为没有任何东西可以参考。
实际参考。 />
如果我分配如下引用;
this->_det);
}
I would expect that I should end up with nothing as there is nothing to
actualy reference.
If I assign the reference as below;
var = getRow()
然后回显结果;
echo
var = getRow()
and then echo the result;
echo
var [''name''];
echo
var[''name''];
echo
这篇关于参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!