PHP OOP中$a = &$b
,$a = $b
和$b = clone $a
之间的区别是什么? $a
是一个类的实例。
答案 0 :(得分:8)
// $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;
并使用References,Object Cloning检查更多信息。
答案 1 :(得分:0)
// $a has same object id as $b. if u set $b = NULL, $a would be still an object
$a = $b;
// $a is a link to $b. if u set $b = NULL, $a would also become NULL
$a = &$b;
// clone $b and store to $a. also __clone method of $b will be executed
$a = clone $b;
答案 2 :(得分:-1)
如果你不知道什么是ZVAL结构,什么是引用,在ZVAL结构中是is_ref,只需花一些时间PHP's garbage collection。