title: How do I access constants from a external required file in PHP?
body: <p>I have this class i making that works if I keep the constants in the class code, but i wanted to access them from an external file that the user can comment or uncomment out c constant value.</p>
  
  <p>it works great this way but I do not want the users rummaging around in the code:</p>
  
  <pre><code>class passwordStringHandler
  {
  
  # const PWDALGO = 'md5';
  # const PWDALGO = 'sha1';
  # const PWDALGO = 'sha256';
  # const PWDALGO = 'sha512';
  const PWDALGO = 'whirlpool';
  
    /* THIS METHOD WILL CREATE THE SALTED USER PASSWORD HASH DEPENDING ON WHATS BEEN
      DEFINED    */
  
  function createUsersPassword()
  {
  
  $userspassword = 'Te$t1234';
  
  $saltedpassword='';    
  
  if ((defined('self::PWDALGO')) &amp;&amp; (self::PWDALGO === 'md5'))
  {
      $saltedpassword = md5($userspassword . $this-&gt;pwdsalt);
      echo("The salted md5 generated hash is: " . $saltedpassword . "&lt;br&gt;");
      return $saltedpassword;
  
  }elseif ((defined('self::PWDALGO')) &amp;&amp; (self::PWDALGO === 'sha1')){
      $saltedpassword = sha1($userspassword . $this-&gt;pwdsalt);
      echo("The salted sha1 generated hash is: " . $saltedpassword . "&lt;br&gt;");
      return $saltedpassword;
  
  }elseif ((defined('self::PWDALGO')) &amp;&amp; (self::PWDALGO === 'sha256')){
      $saltedpassword = hash('sha256', $userspassword . $this-&gt;pwdsalt);
      echo("The salted sha256 generated hash is: " . $saltedpassword . "&lt;br&gt;");
      return $saltedpassword;
  
  }elseif ((defined('self::PWDALGO')) &amp;&amp; (self::PWDALGO === 'sha512')){
      $saltedpassword = hash('sha512', $userspassword . $this-&gt;pwdsalt);
      echo("The salted sha512 generated hash is: " . $saltedpassword . "&lt;br&gt;");
      return $saltedpassword;
  
  }elseif ((defined('self::PWDALGO')) &amp;&amp; (self::PWDALGO === 'whirlpool')){
      $saltedpassword = hash('whirlpool', $userspassword . $this-&gt;pwdsalt);
      echo("The salted whirlpool generated hash is: " . $saltedpassword . "&lt;br&gt;");
      return $saltedpassword;
  
  }
  
  else
  
      echo("No password algro is defined! Edit the [&lt;strong&gt;PWDALGO&lt;/strong&gt;] options in the &lt;strong&gt;systemConfiguration.php&lt;/strong&gt;&lt;br&gt;");  
      return false;
  
  }
  </code></pre>
  
  <p>This works ok cause it is hard coded into the class file:</p>
  
  <p>I want it to work using this:</p>
  
  <pre><code>require ("../configs/systemConfiguration.php");   
  class passwordStringHandler
  {
  </code></pre>
  
  <p>I keep getting the else in my if /else statement it cant find if PWDALGO is defined.</p>
  
  <p>or this way</p>
  
  <pre><code>class passwordStringHandler
  {
  require ("../configs/systemConfiguration.php");
  </code></pre>
  
  <p>I do not know if this is possible since i keep getting an error, I do not think you can include or require files inside the class scope.</p>
  
  <p>in the future if I get this to work I wanted a setup script to check the server to see what encryption types are available and to make a list of the for the user to choose there preferred method of encryption, and then set it automatically for them. and be able to change the encryption method later from a admin control panel.</p>