title: PHP Object Assignment vs Cloning
body: <p>I know this is covered in the php docs but I got confused with this issue . </p>
  
  <p>From the php docs : 
      
  
  <pre><code>$instance = new SimpleClass();
  $assigned   =  $instance;
  $reference  =&amp; $instance;
  $instance-&gt;var = '$assigned will have this value';
  $instance = null; // $instance and $reference become null
  var_dump($instance);
  var_dump($reference);
  var_dump($assigned);
  ?&gt;
  </code></pre>
  
  <p>The above example will output:</p>
  
  <pre><code>NULL
  NULL
  object(SimpleClass)#1 (1) {
  ["var"]=&gt;
   string(30) "$assigned will have this value"
  }
  </code></pre>
  
  <p>OK so I see that <code>$assigned</code> <em>survived</em> the original object (<code>$instance</code>) being assigned to <code>null</code>, so obviously <code>$assigned</code> isn't a reference but a copy of $instance. </p>
  
  <p>So what is the difference between </p>
  
  <pre><code> $assigned = $instance 
  </code></pre>
  
  <p>and </p>
  
  <pre><code> $assigned = clone $instance
  </code></pre>