Last active
May 9, 2016 13:28
-
-
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.
This file contains hidden or 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
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