note 97729 deleted from function.include by danbrown
| From: | danbrown@php.net | Date: | Wed, 05 May 2010 14:12:57 +0000 |
| Subject: | note 97729 deleted from function.include by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168966@lists.php.net to get a copy of this message | ||
Note Submitter: rybadour at gmail dot com
----
Problems with including files inside of files included by other files (Tim describes this problem as
well) originates from an inconsistency in PHP and how it handles including files.
Given a file B that is included in file A, any time you include files in B and the path begins with
"../" the path is no longer relative to B it is relative to A. (It sounds silly I know) I
tested this in PHP 5.* and it's consistently the problems most people have with this. Note,
there isn't a problem when your path does not begin with "../".
Now, I have found a trick to fix this problem. And (although no offense to Tim and others who
offered great solutions) there is a much more elegant way of making this work.
Following my above example, with file A and B to fix the relative pathing do the following:
1. Create a dummy directory in the same directory as B (let's call it dummyDir)
2. Append "dummDir/../" to the beginning of include paths in B.
3. And now the path will work fine.
Ex. originally in B: include("../lib/functions.php"); would not work if there wasn't
a directory above A that contained a directory "lib".
Now we do: include("dummyDir/../../lib/functions.php");
That will now work as intended.