If you do not use namespaces , the best way to do this is to always take into account the absolute path of system files, not relative paths - that is, the path of a file relative to other.
In addition, always use the following magic constants to make it easier to include files:
-
__FILE__
(to reference the current file), and
-
__DIR__
(to reference the current file directory).
For example:
index.php:
<?php
require_once(__DIR__ . '/bootstrap.php');
bootstrap.php:
<?php
require_once(__DIR__ . '/autoload.php');
require_once(__DIR__ . '/config/config.php');
require_once(__DIR__ . '/app/url_router.php');
Now, if you use version 5.3 of PHP or higher, suddenly it's worth thinking about namespaces. So, instead of including the files manually, the organization of the classes takes into account the directory structure - which is much more intuitive.
If you choose this path, it is a good idea to use Composer , which can generate an autoload file and facilitate some aspects of your application.