Skip to content

Instantly share code, notes, and snippets.

@christeredvartsen
Created July 4, 2012 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christeredvartsen/3049155 to your computer and use it in GitHub Desktop.
Save christeredvartsen/3049155 to your computer and use it in GitHub Desktop.
Register simple autoloader
<?php
$paths = explode(PATH_SEPARATOR, get_include_path());
spl_autoload_register(function($className) use ($paths) {
$filename = str_replace(array('_', '\\'), '/', $className) . '.php';
foreach ($paths as $path) {
$absPath = realpath(rtrim($path, '/') . '/' . $filename);
if ($absPath) {
require $absPath;
return true;
}
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment