title: Passing a variable from one php include file to another: global vs. not
body: <p>I'm trying to pass a variable from one include file to another. This is NOT working unless I declare the variable as global in the second include file. However, I do NOT need to declare it as global in the file that is calling the first include. For example:</p>
  
  <hr>
  
  <p>front.inc:</p>
  
  <pre><code>$name = 'james';
  </code></pre>
  
  <hr>
  
  <p>index.php:</p>
  
  <pre><code>include('front.inc');
  echo $name;
  include('end.inc');
  </code></pre>
  
  <p>output: james</p>
  
  <hr>
  
  <p>end.inc:</p>
  
  <pre><code>echo $name;
  </code></pre>
  
  <p>output: nothing</p>
  
  <hr>
  
  <p>IF I declare global $name prior to echoing $name in end.inc, then it works properly. The accepted answer to this post explains that this depends on your server configuration: <a href="https://stackoverflow.com/questions/4572062/passing-variables-in-php-from-one-file-to-another">Passing variables in PHP from one file to another</a></p>
  
  <p>I'm using an Apache server. How would I configure it so that declaring $name to be global is not necessary? Are there advantages/disadvantages to one vs. the other?</p>