3

和在 PHP OOP 中$a = &$b有什么区别?是一个类的实例。$a = $b$b = clone $a$a

4

3 回答 3

9
// $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; 

并通过ReferencesObject Cloning查看更多信息。

于 2012-06-25T07:08:34.893 回答
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;
于 2012-06-25T07:15:14.143 回答
-1

如果你不知道什么是 ZVAL 结构,什么是 refcount,ZVAL 结构中的 is_ref 大约是什么,请花点时间进行PHP 的垃圾回收

于 2012-06-25T07:36:03.240 回答