=& 的目的在 PHP 对象赋值中
这样的声明的确切目的是什么?
$myObj =& $existingObject
这是用 $existingObject
的属性和方法扩展 $myObj
吗?
等号 (=
) 和与号 (&
) 结合在一起有什么作用?
What is the exact purpose of a statement like this?
$myObj =& $existingObject
Is this extending $myObj
with the properties and methods of $existingObject
?
What does the equals sign (=
) and the ampersand (&
) married together here do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,首先,
&=
和=&
是两个不同的东西。是哪一个?&=
是按位,右侧=&
更好地写成= &
(带空格),正在赋值一些东西作为参考。Um first of all,
&=
and=&
are two different things. Which is it?&=
is a bitwise and with the righthand side=&
is better written as= &
(with a space), is assigning something as a reference.根据变量的名称,它们是对象。对象始终通过引用传递,因此
= &
是多余的。Based on the names of the variables, they are objects. Objects are always passed by reference, so
= &
would be redundant.$myObj
成为对$existingObject
的引用,而不是被复制。因此,对$myObj
的任何更改也会更改$existingObject
。 (请参阅本文)$myObj
becomes a reference to$existingObject
instead of being copied. So any change to$myObj
also changes$existingObject
. (see this article)这是通过引用传递。这意味着您对 $existingObject 所做的任何操作也会对 $myObj 进行,因为其中一个是对另一个的引用。
This is a pass by reference. It means anything you do to $existingObject will also be done to $myObj because one is a reference to the other.