=&是什么?在PHP中意味着什么? [英] What does =& mean in PHP?

查看:115
本文介绍了=&是什么?在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.

这篇关于=&是什么?在PHP中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆