title: $_SESSION linking to variable reference across pages?
body: <p>I have a PHP session on my website that I am using to store login info. The basic structure of the array is this:</p>
  <pre><code>$_SESSION = Array(
  
      [uid]=&gt;Int
      [acc]=&gt;Array
      [lastAction]=&gt;Timestamp
  
  )
  </code></pre>
  <p>When I set these session variables in my login PHP script, I set them like this:</p>
  <pre><code>$_SESSION[&quot;uid&quot;] = $uid;
  $_SESSION[&quot;acc&quot;] = array(...);
  $_SESSION[&quot;lastAction&quot;] = time();
  </code></pre>
  <p>This never posed a problem until I got to one script later on where I went to bind some variables using MySQLi. I wanted to retrieve the <code>uid</code> variable from one of my tables, so I went ahead and did this:</p>
  <pre><code>$stmt = $link-&gt;prepare(&quot;SELECT `uid` ... FROM ...&quot;);
  ...
  $stmt-&gt;bind_result($uid, ...);
  </code></pre>
  <p>The statement ran with no problems and the data is all correct but there's a problem with the session now.</p>
  <p>Apparently, <code>$_SESSION[&quot;uid&quot;]</code> is still tied to the reference <code>$uid</code>, even though I'm now on a different page and I didn't pass the variable by reference when setting the session.</p>
  <hr />
  <p>To test this theory, I went ahead and set my session again and ran this code:</p>
  <pre><code>&lt;?php
  
      session_start();
      $uid = 1823479;
      print_r($_SESSION);
  
  ?&gt;
  </code></pre>
  <p>Sure enough, <code>$_SESSION[&quot;uid&quot;]</code> equals 1823479.</p>
  <p>Is this expected behavior? I've never run into this problem before, but since I didn't set the session using references, in my mind this is not expected behavior.</p>
  <h3>Additional Information:</h3>
  <blockquote>
  <p>PHP Ver: 5.3</p>
  </blockquote>