Do not use __autoload... It has several drawbacks (including a limit of one per run). Use spl_autoload_registerif you are on 5.2+ instead .
So what I usually do is have a class:
class AutoLoader {
protected static $paths = array(
PATH_TO_LIBRARIES,
);
public static function addPath($path) {
$path = realpath($path);
if ($path) {
self::$paths[] = $path;
}
}
public static function load($class) {
$classPath = $class;
foreach (self::$paths as $path) {
if (is_file($path . $classPath)) {
require_once $path . $classPath;
return;
}
}
}
}
spl_autoload_register(array('AutoLoader', 'load'));
, , " " , AutoLoader::AddPath($path);. (IMHO).
. , . , , , , , , . , ...
. (, ), , , require 'foo/bar.php';. define('PATH_ROOT', dirname(__FILE__));, (PATH_LIBRARIES, PATH_TEMPLATES ..). , ... (, , )...