title: Casting Session variable in php
body: <p>Why can't i do this</p>
  
  <pre><code>$obj = new User();
  $obj-&gt;emailid = $data-&gt;emailid;
  $obj-&gt;password = $data-&gt;password;
  $_SESSION["userinfo"] = $obj;
  </code></pre>
  
  <p>When i try to access this object back i have following error.</p>
  
  <pre><code>$obj = $_SESSION["userinfo"];
  echo $object-&gt;emailid;
  </code></pre>
  
  <p>Please anyone help me to solve this problem.</p>