title: php how to: save session variable into a static class variable
body: <p>Below code works fine: </p>
  
  <pre><code>&lt;?php session_start();
  
     $_SESSION['color'] = 'blue'; 
  
     class utilities
     {
              public static $color;
  
          function display()
              {
                  echo utilities::$color = $_SESSION['color'];
              }
  
     }
     utilities::display(); ?&gt;
  </code></pre>
  
  <p>This is what I want but doesn't work:</p>
  
  <pre><code>&lt;?php session_start();
  
  $_SESSION['color'] = 'blue'; 
  
  class utilities  {  
       public static $color = $_SESSION['color']; //see here
  
       function display()     
       {      
           echo utilities::$color;    
       }   } utilities::display(); ?&gt;
  </code></pre>
  
  <p>I get this error: <code>Parse error: syntax error, unexpected T_VARIABLE in C:\Inetpub\vhosts\morsemfgco.com\httpdocs\secure2\scrap\class.php on line 7</code></p>
  
  <p>Php doesn't like session variables being stored outside of functions. Why? Is it a syntax problem or what? I don't want to have to instantiate objects because for just calling utility functions and I need a few session variables to be stored globally. I do not want to call a <code>init()</code> function to store the global session variables every time I run a function either. Solutions?</p>