本文介绍了PHP OOP中的$ a =& $ b,$ a = $ b和$ a = clone $ b之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ a =& $ b
, $ a = $ b
和 $ b = clone $ a
在PHP OOP? $ a
是类的实例。
What is the difference between $a = &$b
, $a = $b
and $b = clone $a
in PHP OOP? $a
is an instance of a class.
推荐答案
// $a is a reference of $b, if $a changes, so does $b.
$a = &$b;
// assign $b to $a, the most basic assign.
$a = $b;
// This is for object clone. Assign a copy of object `$b` to `$a`.
// Without clone, $a and $b has same object id, which means they are pointing to same object.
$a = clone $b;
并使用,对象克隆
And check more info with References, Object Cloning.
这篇关于PHP OOP中的$ a =& $ b,$ a = $ b和$ a = clone $ b之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!