'&';PHP中函数名前签名
你能给我解释一下这两种功能的区别吗'&';PHP中函数名前签名,php,Php,你能给我解释一下这两种功能的区别吗 function &a(){ return something; } 及 谢谢 第一个返回对something的引用,第二个返回something的副本 在第一种情况下,当调用方修改返回值时,something将被修改为全局变量do 在第二种情况下,将副本修改为对源无效。函数名前的“与”表示函数将返回对变量的引用,而不是值 据此, function b(){ return something; } Returning by refe
function &a(){
return something;
}
及
谢谢 第一个返回对
something
的引用,第二个返回something
的副本
在第一种情况下,当调用方修改返回值时,something
将被修改为全局变量do
在第二种情况下,将副本修改为对源无效。函数名前的“与”表示函数将返回对变量的引用,而不是值 据此,
function b(){
return something;
}
Returning by reference is useful when you want to use a function to find to which
variable a reference should be bound. Do not use return-by-reference to increase
performance. The engine will automatically optimize this on its own. Only return
references when you have a valid technical reason to do so.