Skip to content

Instantly share code, notes, and snippets.

@Ferreiramg
Created July 9, 2013 00:52
Show Gist options
  • Save Ferreiramg/5953774 to your computer and use it in GitHub Desktop.
Save Ferreiramg/5953774 to your computer and use it in GitHub Desktop.
psr-0 autoload
define("DS", DIRECTORY_SEPARATOR);
set_include_path(
implode(PATH_SEPARATOR, array(dirname(__DIR__), get_include_path())
));
$psr = array(
'\\' => DS,
'_' => DS
);
spl_autoload_register(function($class)use($psr) {
$filename = strtr($class, $psr) . ".php";
foreach (explode(PATH_SEPARATOR, get_include_path()) as $paths) {
$paths .=DS . $filename;
if (is_file($paths)) {
require_once $paths;
return true;
}
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment