Created
July 4, 2012 19:30
-
-
Save christeredvartsen/3049155 to your computer and use it in GitHub Desktop.
Register simple autoloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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