Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Created February 22, 2014 08:28
Show Gist options
  • Save tournasdim/9150482 to your computer and use it in GitHub Desktop.
Save tournasdim/9150482 to your computer and use it in GitHub Desktop.
A simple ClassLoader (autoloader) with spl_autoload_register function .
/*** nullify any existing autoloads ***/
spl_autoload_register(null, false);
/*** specify extensions that may be loaded ***/
spl_autoload_extensions('.php');
/*** class Loader ***/
function classLoader($class)
{
//$filename = ucfirst(strtolower($class) . '.php') ;
$filename = $class.'.php' ;
$dirs = array(__DIR__ .'/' , __DIR__.'/classes/') ;
foreach ($dirs as $dir)
{
if (file_exists($dir.$filename))
{
include $dir.$filename ;
break ;
}
}
}
/*** register the loader functions ***/
spl_autoload_register('classLoader');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment