是否有简单的PHP代码来区分“将对象作为引用传递"?vs “将对象引用作为值传递"? [英] Is there simple PHP code to distinguish "Passing the object as reference" vs "Passing the object reference as value"?
本文介绍了是否有简单的PHP代码来区分“将对象作为引用传递"?vs “将对象引用作为值传递"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这与问题有关:如何"?&"运算符在 PHP 函数中工作?
是否有简单的代码来显示两者之间的区别
Is there simple code to show the difference between
将对象作为引用传递
对比
将对象的引用作为值传递?
passing the object's reference as value?
推荐答案
您可以通过引用将变量传递给函数.这个函数就可以修改原来的变量了.
You can pass a variable to a function by reference. This function will be able to modify the original variable.
可以在函数定义中通过引用定义段落:
You can define the passage by reference in the function definition:
<?php
function changeValue(&$var)
{
$var++;
}
$result=5;
changeValue($result);
echo $result; // $result is 6 here
?>
这篇关于是否有简单的PHP代码来区分“将对象作为引用传递"?vs “将对象引用作为值传递"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文