PHP Object Assignment vs Cloning

前端 未结 7 1206
后悔当初
后悔当初 2020-11-29 05:34

I know this is covered in the php docs but I got confused with this issue .

From the php docs :

$instance = new SimpleClass();
$assigned   =  $ins         


        
相关标签:
7条回答
  •  $assigned = $instance 
    

    Above will assign $instance to $assigned, the most basic assign.

     $assigned = clone $instance 
    

    This is for object clone. Assign a copy of object $instance to $assigned.

    Without clone, $assigned and $instance has same object id, which means they are pointing to same object.

    0 讨论(0)
提交回复
热议问题