Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Last active May 9, 2016 13:28
Show Gist options
  • Save igoralves1/ec6c6dd92df8fcaaacd3d8c4a88e0628 to your computer and use it in GitHub Desktop.
Save igoralves1/ec6c6dd92df8fcaaacd3d8c4a88e0628 to your computer and use it in GitHub Desktop.
PHP - Autoload. Load CLasses if not found. Works with regular or static classes.
spl_autoload_register(function ($class_name) {
include './class/'.$class_name . '.php';
});
================== or ========================
function __autoload($className) {
$className = str_replace("..","", $className);
require_once ("./class/$className.php");
}
//Note: Class must have same name of the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment