Skip to content

Instantly share code, notes, and snippets.

@nekoya
Created May 28, 2009 07:19
Show Gist options
  • Save nekoya/119157 to your computer and use it in GitHub Desktop.
Save nekoya/119157 to your computer and use it in GitHub Desktop.
/**
* PHP Autoloader Example.
*/
/**
* __autoload in global space
*/
function __autoload($class) {
$dirname = dirname(__FILE__);
$class = preg_replace('/_/', DIRECTORY_SEPARATOR, $class);
$filename = $dirname . DIRECTORY_SEPARATOR . $class . '.class.php';
require $filename;
}
/**
* AutoLoader class based
*/
class AutoLoader {
/**
* autoloader
*
* @static
* @access public
*/
static function __load($class)
{
$dirname = dirname(__FILE__);
$class = preg_replace('/_/', DIRECTORY_SEPARATOR, $class);
$filename = $dirname . DIRECTORY_SEPARATOR . $class . '.class.php';
require $filename;
}
}
spl_autoload_register( array( 'AutoLoader', '__load' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment