title: How to Cast Objects in PHP
body: <p>Ive some classes that share some attributes, and i would like to do something like:</p>
  
  <pre><code>$dog = (Dog) $cat;
  </code></pre>
  
  <p>is it possible or is there any generic work around?</p>
  
  <p>Its not a superclass, or a interface or related in any way. They are just 2 different classes i would like php map the attributes from a cat class to a dog and give me the new object. –</p>
  
  <p>i guess i have to specify a little bit more cause seem like a senseless thing to do.</p>
  
  <p>i've classes that inherits from different parent classes cause i've made an inheritance tree based on the saving method, maybe my bad from the beginning, but the problem is that i have a lot of classes that are practically equal but interacts one with mysql and the other one with xml files. so  i have:</p>
  
  <pre><code>class MySql_SomeEntity extends SomeMysqlInteract{}
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Xml_SomeEntity extends SomeXmlInteract{}
  </code></pre>
  
  <p>its a little bit deeper tree but the problem its that. i cant make them inherits from the same class cause multiple inheritance is not allowed, and i cant separate current interaction with superclases cause would be a big trouble.</p>
  
  <p>Basically the attributes in each one are practical the same.</p>
  
  <p>since i have a lot of this matching classes i would like to do some generic casting or something like it that can converts (pass the values to each attribute) and but im trying to search the simplest way to everyone of this classes. </p>