title: PHP: require doesn't work as it should
body: <p>I have a directory root:</p>
  
  <pre><code>index.php
  includes/
      template.php
      testfile.php
      phpFiles/
          processInput.php
          testfile.php
  </code></pre>
  
  <p>index.php:</p>
  
  <pre><code>require_once("includes/template.php");
  </code></pre>
  
  <p>template.php:</p>
  
  <pre><code>require_once("includes/phpFiles/processInput.php")
  </code></pre>
  
  <p>processInput.php:</p>
  
  <pre><code>require_once("testfile.php")
  require_once("../testfile.php")
  </code></pre>
  
  <p>This code will work when you run index.php, of course it will not work when you run template.php.</p>
  
  <p>As you can see, index.php includes template.php like normal. But in template.php, you have to include like if you are in the directory that index.php is in. But then, in processInput.php, you include as if you are in the directory that processInput.php is in.</p>
  
  <p>Why is this happening, and how can I fix it so that the include path is always the directory of the file that the require is done in? The second included file have the same include path as the requested file, but the next one does not.</p>
  
  <p>Thanks for your help!</p>
  
  <p>EDIT: The strange thing is that I've included classes in a class folder. And it included other files as it is supposed to, even though the paths are relative. WHY does this happen, and how can I fix it?</p>
  
  <p>VERY IMPORTANT EDIT: I just realized that all this is because in my example, the inclusion in includes/phpFiles/processInput.php includes a file in the same directory: require_once("file in same dir.php"); This is the reason. If you are including a file with out specifying anything more than the filename, the include_path is actually the dir where the file the require is written in is in. Can anyone confirm this?</p>