Skip to content

Instantly share code, notes, and snippets.

@BaylorRae
Created August 31, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaylorRae/3559742 to your computer and use it in GitHub Desktop.
Save BaylorRae/3559742 to your computer and use it in GitHub Desktop.
<?php
// Allows multiple __autoload stacks
// and keeps autoloader in Huck class
spl_autoload_register(array('Huck', 'autoload'));
class Huck {
public static function autoload($class_name) {
if( substr($class_name, 0, 5) === 'Huck_' ) {
$file = dirname(__FILE__) . '/' . substr($class_name, 5) . '.php';
if( file_exists($file) )
require_once $file;
}
}
}
?>
<?php
function __autoload($class_name) {
// looks for 'classes/user.php';
$file = 'classes/' . strtolower($class_name) . '.php';
if( file_exists($file) )
require_once $file;
}
/*
Because the User class has not been included on this page
PHP will run `__autoload` and try to include it automatically
*/
$user = new User;
// do stuff with $user
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment