PHP OOP中的$ a =& $ b,$ a = $ b和$ a = clone $ b之间的差异 [英] Difference between $a=&$b , $a = $b and $a= clone $b in PHP OOP

查看:168
本文介绍了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之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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