title: How to prevent that a PHP session variable is modified after unserialize()
body: <p>I have saved an PHP object (of the class <code>login</code>) into the session variable <code>$_SESSION["login"]</code>. The class <code>login</code> has the methods <code>__sleep()</code> and <code>__wakeup()</code>.
  And before I save the object into the session, I apply the serialize method on it.</p>
  
  <p>On another page I use this session variable. If I execute <code>unserialize($_SESSION["login"])</code> the first time I have no problem. But if I use the same command a second time, the result changes.</p>
  
  <pre><code>    var_dump($_SESSION["login"]); // everything is how expected and how I saved it
      $temp = $_SESSION["login"]; // here I try to copy the content of the session variable
      $un_ser = unserialize($temp); // I use unserialize to get the original object
      var_dump($_SESSION["login"]); // Problem: not the same as before! Why has it changed?
  </code></pre>
  
  <p>The problem is that I want to read the <code>login</code>-object with <code>unserialize($_SESSION["login"])</code> for more than only one time but currently it seems to me that it is not possible because the session variable changes after <code>unserialize(...)</code>.</p>
  
  <p>To be concrete the string, which I save into the session, is originally:        </p>
  
  <pre><code>O:24:"BSHelper\login":2:{s:12:"*logged_in";b:1;s:9:"*lehrer";O:22:"BSCore\lehrer":7:{s:12:"*id_lehrer";s:1:"1";s:13:"*geschlecht";s:4:"Herr";s:11:"*nachname";s:10:"testsurname";s:17:"*unterrichtsart";s:6:"Praxis";s:21:"*unterrichtsartKurz";s:1:"P";s:11:"*farbcode";s:7:"#F0BB86";s:8:"*email";s:26:"test@mail.com";}}
  </code></pre>
  
  <p>but after <code>unserialize(...)</code> the session variable changed to this</p>
  
  <pre><code>O:24:"BSHelper\login":2:{s:12:"*logged_in";b:0;s:9:"*lehrer";N;}
  </code></pre>
  
  <p>I think that it really makes sense to be able to access a whole object out of the session variable because that makes it possible to access values and especially methods of the object.</p>