=&是什么?在PHP中意味着什么?
问题描述:
考虑:
$smarty =& SESmarty::getInstance();
&
的作用是什么?
答
它通过引用传递.这意味着它不会创建所传递的值的副本.
It passes by reference. Meaning that it won't create a copy of the value passed.
请参阅: http://php.net/manual/en/language.references.php (请参见亚当的答案)
See: http://php.net/manual/en/language.references.php (See Adam's Answer)
通常,如果您传递这样的内容:
Usually, if you pass something like this:
$a = 5;
$b = $a;
$b = 3;
echo $a; // 5
echo $b; // 3
如果更改第二个变量($b
),则不会修改原始变量($a
).如果您通过引用:
The original variable ($a
) won't be modified if you change the second variable ($b
) . If you pass by reference:
$a = 5;
$b =& $a;
$b = 3;
echo $a; // 3
echo $b; // 3
原稿也被更改.
在传递对象时没有用,因为默认情况下它们将通过引用传递.
Which is useless when passing around objects, because they will be passed by reference by default.