title: How to Initialize a Instance of a PHP Class using another Object Instance?
body: <p>What would be a good way <em>(along with any pros and cons)</em> of initializing an instance of a PHP class with another object of the same class <em>(ideally in PHP 4.x)</em>?</p>
  <p>Here in <code>initialize()</code> is essentially what I'd like to be able to do (example is extremely simplified from my use-case, see below):</p>
  <pre><code>$product = new Product('Widget');
  $product2 = new Product('Widget #2');
  $product-&gt;initialize($product2);
  echo $product-&gt;name;  // echos &quot;Widget #2&quot;
  
  class Product {
   var $name;
   function __constructor($name) {
     $this-&gt;name = $name;
   }
   function initialize($product) {
     // I know this cannot be done this way in PHP. 
     // What are the alternatives and their pros &amp; cons?
     $this = $product;  
   }
  }
  </code></pre>
  <p><em>I know this may not be &quot;good programming practice&quot;; with 20+ years programming experience on other languages I know a bit about what's good and what's not. So hopefully we won't get hung up on if doing this makes sense or not. I have a use-case working with some open-source code that I can't change so please just bear with me on my need for it. I'm actually trying to create an OOP wrapper around some really ugly array code buried deep in the core of WordPress.</em></p>
  <p><em>I'm trying to write it so in future versions they can move away from the ugly array-based code because everyone will be using the new API that otherwise fully encapsulated these nasty arrays. But to make it work elegantly I need to be able to do the above (in PHP 4.x) and I don't want to write code that just copies the properties.</em></p>
  <p>Thanks in advance for your help.</p>
  <h2>UPDATE</h2>
  <p>Many of you are suggesting <code>clone</code> but unless I misunderstand that doesn't address the question. <code>clone</code> makes a copy; that's not the crux of the question. <strong>I'm instead trying to get the constructed object to <em>&quot;become&quot;</em> the object passed in.</strong> At this point I'm assuming there isn't a way to do that based on the fact that 0 out of 5 answers have suggested anything but I'll wait a bit longer before selecting a best in case it was simply that my questions was unclear.</p>