Skip to content

Instantly share code, notes, and snippets.

@lishiyo
Created April 12, 2015 04:40
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 lishiyo/c886ca4491daf6484b3e to your computer and use it in GitHub Desktop.
Save lishiyo/c886ca4491daf6484b3e to your computer and use it in GitHub Desktop.
PHP Examples - Autoload
/*
Autoloading is very nifty, and is used in a lot of large frameworks - it allows you to load the file that a class is written in automatically when you try to instantiate it. The advantage of this is that only classes that you want to instantiate & use will be included in your page and will keep memory usage down.
*/
// Using an anonymous function
spl_autoload_register(function($class){
include_once('includes/' . $class . '.class.php')
});
// Using a named function
function autoload_class($class){
include_once('includes/' . $class . '.class.php');
}
spl_autoload_register('autoload_class');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment