What is proper way to declare require'd elements within PHP in different directories?
<p>I make use of several 'require()' statements on my site. In some of these require statements, additional 'require' elements are placed. The issue I sometimes face however is that the directory called for the first require may be different than the second and in turn cause the site to look in the wrong place.</p>

<p>For example:</p>

<p>Let's assume the site structure has 2 main folders: X and Y. Within Y is a sub folder called Z. </p>

<p>A file in folder X, called page.php, makes use of a require statement for a file in Y called 'function.php'. Function.php however makes use of an additional require statement in Z called 'constants.php'.</p>

<p>page.php (within X) looks like:</p>

<blockquote>
  <p>require('../Y/function.php');</p>
</blockquote>

<p>and function.php (within Y) looks like:</p>

<blockquote>
  <p>require('Z/constants.php');</p>
</blockquote>

<p>The issue I face is that when X is essentially trying to call Z's constants file, it treats it as if the folder Z laid in its own subdirectory.</p>

<p>i.e. page.php makes 2 require calls require('../Y/function.php'); and require('Z/constants.php'); &lt;- which does not exist.</p>

<p>I know I <em>could</em> use absolute paths but I am constantly switching between windows and linux environments and it would be a giant PITA to go back and forth between the two formats.</p>

<p>Any suggestions?</p>

<h2>EDIT</h2>

<p>The strangest part is, sometimes the above issue works. I cannot figure out why quite yet but it seems like the issue may actually be that going forward in directories can be autocorrected but going backwards (i.e. being at level 3 in one folder and jumping back causes issues)</p>
