I\'ve never seen anything like this.
File structure:
The path used in your includes are not relative to the file the includes are : they are relative to the include_path.
Which means that using relative paths with includes/requires will generally not do what you expect it to...
The solution that's generally used is to work with absolute paths ; this way, you are sure what gets included.
Of course, using absolute paths in your code is bad (it will work on one server, but not another, when your application is deployed to another path) ; so, the solution is to :
The full path to the file you're in can be obtained with __FILE__.
Which means the directory to the current file (the file that instruction is written in) can be obtained with dirname(__FILE__).
After that, it's only a matter of writing the correct paths.
For example, in stuff.php, you'd use :
require(dirname(__FILE__) . "/constants.php");
While, in base.php , you'd use :
require(dirname(__FILE__) . "/../includes/stuff.php");
Something that I found helpful was checking getcwd() (get current working directory) which would return the folder path of the file from which it was included from. If the include file was being called beneath (down a level) of my top directory, then I could calculate and prepend the appropriate number of ../s.
I.e., if I know my include's files were in topfolder/css/blah.css then I could check the value of getcwd() in my included file like this:
$leaveDirectoryIfNecessary = "";
// Grab the last 9 characters of the directory name
if (substr(getcwd(), -9) != "topfolder") {
$leaveDirectoryIfNecessary = "../";
}
And then I would echo $leaveDirectoryIfNecessary before every file I was referencing in the include file like so:
<link rel="stylesheet" type="text/css" href="<?php echo $leaveDirectoryIfNecessary; ?>css/goodstuff.css">
Notably, this presumes you don't duplicate the name of your parent / top level folder anywhere in your subfolder tree.
You would also need to have some sort of loop and count the number of forward slashes in the current working directory after 'topfolder' if you happen to have a deeper folder structure beyond one level deep that the include file is included from.