title: How does object serialize/unserialize work?
body: <p>I was reading about serialize/unserialize concepts of PHP. I was wondering how they are stored in the filesystem/db. I guess it is in the binary format. However, I wonder how entire class is stored? I understood that data in the data member can be stored but how are the methods stored?</p>
  
  <p>I mean, how does PHP know what code is written inside the function of say, <code>someFunc()</code>?</p>
  
  <pre><code>$obj = new ClassName();
  $obj-&gt;someFunc();
  $serial = serialize($obj);
  $unserialobj = unserialize($serial);
  $unserialobj-&gt;someFunc();
  </code></pre>
  
  <p>PHP can know what to do at line #2, but how it know what to do at line #5 which is an unserialized object? Does it save the code as well?</p>