Skip to content

Instantly share code, notes, and snippets.

@fordnox
Created August 9, 2011 19:52
Show Gist options
  • Save fordnox/1135017 to your computer and use it in GitHub Desktop.
Save fordnox/1135017 to your computer and use it in GitHub Desktop.
Simplest possible autoloader for PHP classes. Can be used and for namespaces
<?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