How can I include files using paths relative to where the file resides?
<p>Imagine I have two directories, <strong>foo</strong> and <strong>bar</strong> in a parent directory, and these directories contain some PHP files:</p>

<pre><code>/
/index.php

/foo
/foo/functions.php
/foo/stuff.php

/bar
/bar/doodie.php
</code></pre>

<p>Let's say:</p>

<ol>
<li><code>functions.php</code> includes <code>stuff.php</code></li>
<li><code>index.php</code> includes <code>functions.php</code></li>
<li><code>doodie.php</code> includes <code>functions.php</code></li>
</ol>

<p>Based upon this structure, when <code>index.php</code> is run, it will look for <code>/foo/functions.php</code>in the <code>/foo</code> directory. <strong>However</strong>, <code>stuff.php</code> must be included using the relative path according to the location of <code>index.php</code>. This works, in the case of when <code>index.php</code> is run. <strong>It doesn't work</strong> when <code>doodie.php</code> is called because <code>functions.php</code> looks for <code>stuff.php</code> in the <code>/foo</code> directory, which doesn't exist when the location is <code>/bar</code>.</p>

<p>Is it possible to include files according to where they reside instead of where they are called from, without using absolute paths (and <a href="http://stackoverflow.com/a/3243015/613857">session variables</a>)?</p>

<p>I apologize if this wasn't clear, it was really tough to describe this...</p>
