Created
February 22, 2014 08:28
-
-
Save tournasdim/9150482 to your computer and use it in GitHub Desktop.
A simple ClassLoader (autoloader) with spl_autoload_register function .
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
/*** 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