title: Global PHP App Configuration Constants & "Includes"
body: <p>I am currently creating/re-building a fairly sizable PHP app/website that uses a few different API's and interfaces with a database. And so, I have to store API keys, App Keys and other such configuration data so they are all centrally accessible by all of the different files/pages.</p>
  
  <p>Currently, I'm declaring variables in the global context and including them using require_once():</p>
  
  <pre><code>&lt;?php //config.php
  $API_KEY['somename']    =    "THIS_IS_MY_API_KEY";
  $API_KEY['othername']   =    "ANOTHER_API_KEY";
  
  $APP_ID['somename']     =    "APP_ID_HERE";
  $APP_ID['othername']    =    "OTHER_APP_ID";
  
  //So on and so forth, with all of the API data I need, like API URLs
  //Also, I'm declaring things like this...
  
  $__SITEWIDE_KILLSWITCH  =    false;
  $__DEBUG_MODE           =    false;
  $__DISPLAY_ERRORS       =    false;
  ?&gt;
  </code></pre>
  
  <p>Then, In my other files, I reference these variables like this:</p>
  
  <pre><code>require_once('path/to/config.php');
  </code></pre>
  
  <p>Only downside is that if I have to reference them in functions, since they are not superglobals like the <code>$_GLOBALS</code> or <code>$_SESSION</code> variables, for instance, I have to do this:</p>
  
  <pre><code>function database_connect( ... ) {
      global $API_KEY, $APP_ID, $API_URL; //etc...
      ...
      ...
  }
  </code></pre>
  
  <p>I want to avoiding passing in my API key's in through the function if I can. I am hoping to get some best practices on declaring site-wide global constants and maybe avoid calling the <code>global</code> keyword at the beginning of each function. </p>
  
  <p>Should I be using <code>const</code> in my declarations? Any benefit in using the define() function?</p>
  
  <p>Am I doing the right thing with <code>require_once()</code> or is there a better way to do this? </p>
  
  <p>What do you all think? How should I be doing this?
  Thanks!</p>