title: Php abstract class site configuration
body: <p>i have a config class which is an abstract class. I would like to set it up so it automatically detects which server the site is on and then assigns appropriate constants. I get an error on line ten <code>$this-&gt;hostName = $_SERVER['SERVER_NAME'];</code> expecting `T_FUNCTION.
  What is the correct way to do this and is there a better way to do this? Here is the first part of my class</p>
  
  <pre><code>abstract class config{
  
   public $hostName;
   public $hostSlices;
   public $domain;
  echo $_SERVER['SERVER_NAME'];
  //strips out the "www" from the server name but only if it has the name on it . 
  $this-&gt;hostName = $_SERVER['SERVER_NAME'];
  $this-&gt;hostSlices = explode(".",$this-&gt;hostName);
  if($this-&gt;hostSlices[0]=="www"){array_shift($this-&gt;hostSlices);}
  $this-&gt;domain = join(".",$this-&gt;hostSlices);
  
  //depending on which domain is used, different config setup is used. 
  switch ($this-&gt;domain){
      case "localhost":*/
  
    const HOST = "localhost";//would http://localhost/ work as well. In that case, then this and the SITE_ROOT  could be the same variable and i would preferentially set them depending on the host that the site is on.
    const USER = "root";
    const PWD = "xxxxxxx";
    const NAME = "hurunuitconz";//database name
  
    //public $name = "hello from the config class";//you cannot access variables from an abstract class  you should define constants and then the can be used anywhere
  
   ###########Location of file groups########
    const SITE_ROOT = "http://localhost";
    const ADMIN_IMAGES = 'http://localhost/images/user_images/admin_images';
  
          break;
  
  
  
      case "charles.hughs.natcoll.net.nz":
  
    const HOST = "charles.hughs.natcoll.net.nz";//would http://localhost/ work as well. In that case, then this and the SITE_ROOT  could be the same variable and i would preferentially set them depending on the host that the site is on.
    const USER = "charles_andrew";
    const PWD = "xxxxxxx";
    const NAME = "charles_hurunuitconz";//database name
   ###########Location of file groups########
    const SITE_ROOT = "http://charles.hughs.natcoll.net.nz/_Assignments/Industry/www";//this is just confusing the way natcoll makes us do this. 
    const ADMIN_IMAGES = 'http://charles.hughs.natcoll.net.nz/_Assignments/Industry/www/images/user_images/admin_images';
  
          break;
      }
  </code></pre>