title: "Namespaces", constants and multiple PHP includes
body: <p>I have some PHP code similar to the following: </p>
  
  <pre><code>foreach ($settingsarray as $settingsfile)
  {
      include ($settingsfile);
      // do stuff here
  }
  </code></pre>
  
  <p>$settingsarray is an array of file names from a particular folder.</p>
  
  <p>The problem is, that each $settingsfile defines constants (with the same names), which of course, can not be redefined. </p>
  
  <p>What possible methods are there to prevent errors occurring in this situation? </p>
  
  <p>Two options I can think of include, changing all the constants to variables and using PHP namespaces.</p>
  
  <p>However, I'm not sure how I would go about using namespaces, it would require the declaration at the start of every $settingsfile? Is there a method of isolating constants, ariables and functions without using namespaces?</p>
  
  <p>What I would really love, is to be able to do something as simple as:</p>
  
  <pre><code>foreach ($settingsarray as $settingsfile)
  {
      {//added braces to indicate where the isolation is
          include ($settingsfile);
          // do stuff here
      }//what happens in here does not affect what happens outside of here
  }
  </code></pre>
  
  <p>I should just note, this is part of a new feature, and is the only part of the code that loads all the $settingsfiles. The rest of the code only ever loads one file at a time. One reason I am using constants is so that I don't have to worry about defining variables "global" to be able to access them inside functions.</p>