title: PHP variable name conflict with session variables
body: <p>I have the following segment of code that someone else has written, and that I'm trying to fix:</p>
  
  <pre><code>function calc() {
      require_once("db.php");     
      connect();
  
      $a = split("#", $_SESSION['freight']);
      $loc = $a[0];
  
      $r = mysql_query("SELECT `price`, `gst` FROM `freight` WHERE `location`='$loc'");
      $arr = mysql_fetch_array($r);
      $_SESSION['freight'] = $loc."#".$arr['price'];      
  
      return $arr['price'];
  }
  
  function ajaxFunction () {
      $_SESSION['freight'] = $_GET['loc']; 
      $freight = calc();
      echo number_format($freight, 2);
      return;
  }
  </code></pre>
  
  <p>It ain't pretty, I am just trying to fix it. </p>
  
  <p>Now I have noticed the bug seems to stem from the fact $freight = calc(). After that line, $freight will equal say $10 (the $arr['price'] value). <strong>BUT</strong> the $_SESSION['freight'] will also equal $10, and just $10, as if it was the same variable as $freight. What ever I set $freight to, the $_SESSION['freight'] also becomes. </p>
  
  <p>If I change $freight in the ajax function to $freight2 it doesn't alter the session variable. Is this something major that I don't know about PHP? That variable names share the same namespace as session variables?</p>
  
  <p>The question overall is:
  Does changing $a alter $_SESSION['a'] in anyway? Because it really seems like it does. </p>