title: Echoing session variables in php
body: <p>I know that in php I can put a variable name inside a quoted string when I use echo, but I apparently can't do this with a session variable.  Can anyone explain why? </p>
  
  <p>Here is the code, with the "offending" php commented out:</p>
  
  <pre><code>&lt;?php
  session_start();
  $test = 100;
  $_SESSION['test'] = 200;
  ?&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;p&gt;&lt;?php echo($test."&lt;br /&gt;");?&gt;&lt;/p&gt;
    &lt;p&gt;&lt;?php echo("$test"."&lt;br /&gt;");?&gt;&lt;/p&gt;
    &lt;p&gt;&lt;?php echo($_SESSION['test']."&lt;br /&gt;");?&gt;&lt;/p&gt;
    &lt;p&gt;&lt;?php //echo("$_SESSION['test']"."&lt;br /&gt;");?&gt;&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And the output looks like this:</p>
  
  <pre><code>100
  
  100
  
  200
  </code></pre>
  
  <p>But if I uncomment the offending code line:</p>
  
  <pre><code>  &lt;p&gt;&lt;?php echo("$_SESSION['test']"."&lt;br /&gt;");?&gt;&lt;/p&gt;
  </code></pre>
  
  <p>I get no output and the following error:</p>
  
  <pre><code>Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in - on line 14
  </code></pre>
  
  <p>So I can go on my merry way knowing how to do it correctly (just keep the session variable outside of the double quotes), but I would really like to understand why this doesn't work for session variables.</p>
  
  <p>Thanks!</p>