title: How do I create a copy of an object in PHP?
body: <p>It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object.</p>
  
  <p>Here's a simple, contrived proof:</p>
  
  <pre><code>&lt;?php
  
  class A {
      public $b;
  }
  
  
  function set_b($obj) { $obj-&gt;b = "after"; }
  
  $a = new A();
  $a-&gt;b = "before";
  $c = $a; //i would especially expect this to create a copy.
  
  set_b($a);
  
  print $a-&gt;b; //i would expect this to show 'before'
  print $c-&gt;b; //i would ESPECIALLY expect this to show 'before'
  
  ?&gt;
  </code></pre>
  
  <p>In both print cases I am getting 'after'</p>
  
  <p>So, how do I pass <strong>$a</strong> to <strong><em>set_b()</em></strong> by value, not by reference?</p>