title: Using already defined constants in PHP
body: <p>This is a bit long but I hope to get some insight form you guys.</p>
  <p>I'm writing this inhouse tool for Wordpress. Today we have some 150+ sites alive and this tool helps me manage them. I'm using the file wp-config.php to get database name, server, user etc. With that information I'm getting the important data out of each sites database. That could be used template etc. Together with version numbers I can keep track of updates etc. It's useful and timesaving. The problem is not wordpess specific so that's why I bring it here.</p>
  <p>Currently I'm reading the wp-config.php file and parsing out that information and that's because the wp-config.php file can be somewhat differently written with extra spaces around ' or no spaces.</p>
  <p>The thing is that in wp-config.php for all sites, the key variables are set as constants. It could look like this:</p>
  <pre><code>define( 'DB_HOST', 'localhost' );
  define( 'DB_USER', 'mydbuser' );
  </code></pre>
  <p>So if I echo DB_HOST I get <em>localhost</em> and so on. I'm wondering if I can use those directly without parsing it out.</p>
  <p>But, and here's the crux of the biscuit, I have 150 sites which all are using the same constants, so when looping thru all sites folders and getting the info using 'require_once' and building a list of the sites in-memory I only get the first DB_HOST and DB_USER. That's because it is a constant and we cannot change that. I knew this but I give this a try anyway.</p>
  <p>I've tried setting up a second function so that PHP would magically ”forget&quot; the constants but of course it doesn't. Once DB_HOST is set it is.</p>
  <p>Is there any way I can use the already defined constants from all these wp-config.php files with out the first constants blocking the next one with the same name?</p>
  <p>The question is a bit fuzzy but I hope you understand what I'm trying to do here.</p>
  <h2>Edit:</h2>
  <p>This is a mockup of the function that's used in the loop that walks thru all wordpress folders.</p>
  <p><strong>$in</strong> is the name/path of the folder that the sites sits in.</p>
  <pre><code>function templatename($in){
  require_once($in.'/wp-config.php'); 
  
  $dbusr = DB_USER;
  $dbpass = DB_PASSWORD;
  $dbname = DB_NAME;
  $dbpref = $databasprefix;
  $dbsrv = DB_HOST;
  
  // executing SQL connection with the info above retrieving $data 
  
  return $data;
  
  }
  </code></pre>
  <p>So calling the <code>function templatename(kalle);</code> for the folder <em>kalle</em> will return the template name <em>Twentytwenty</em>.</p>