Created
August 9, 2011 19:52
-
-
Save fordnox/1135017 to your computer and use it in GitHub Desktop.
Simplest possible autoloader for PHP classes. Can be used and for namespaces
This file contains hidden or 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 | |
spl_autoload_register('autoloader'); | |
function autoloader($className) | |
{ | |
if(strpos($className, '\\') !== false) { | |
$className = str_replace('\\', DIRECTORY_SEPARATOR, $className); | |
} | |
if(strpos($className, '_') !== false) { | |
$className = str_replace('_', DIRECTORY_SEPARATOR, $className); | |
} | |
require_once($className.'.php'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment