PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Autoload

Autoload facility allows to load classes on-demand.
 
function __autoload($class) {
    require_once str_replace("_", "/", $class);
}

$obj = new Article_Model();
The Standard PHP Library (SPL) offer a quick solution.
 
//Register an autoload function

function myAutoLoader($className) {
    include("classes/$className.php");
}

spl_autoload_register("myAutoLoader");

//Register another autoload function

function myOtherAutoLoader($className) {
    include("include/$className.php");
}

spl_autoload_register("myOtherAutoLoader");

$obj  = new MyClass1();
$obj2 = new MyClass2();  
... 7 lines
 

Questions    
Class reflection

        A B C D E F
🔔
1/1