title: How to copy a CakePHP Entity
body: <p>I'm writing a method that copies an object. Instead of manually setting each property manually, it would be more robust to just loop over the original object's properties...</p>
  
  <pre><code>//Booo
  $new-&gt;name = $old-&gt;name;
  $new-&gt;color = $old-&gt;color;
  ...
  
  //Oh yeah...
  foreach ($old as $prop=&gt;$val){
      $new-&gt;$prop = $val;
  }
  unset $new-&gt;id;
  </code></pre>
  
  <p>It appears that CakePHP entities cannot be iterated over in this way. I tried using <code>$old-&gt;toArray()</code>, which basically works... but has the drawback of converting all the associations to arrays also, which is screwing this up for me down stream.</p>
  
  <p>How do I loop over the $old properties without converting all the data types?</p>
  
  <p><strong>Update</strong>: 
  Mark brought to my attention the existence of a <a href="http://api.cakephp.org/3.1/class-Cake.Database.Expression.QueryExpression.html#___clone" rel="nofollow"><code>__clone()</code></a> method. Sounds like it does exactly what I need but I'm still figuring out how to use it.</p>