Memory App
Programming
 




Autoload facility allows to load classes on-demand.

<?php

    function __autoload($class) {
        require_once str_replace("_", "/", $class);
    }

    $obj = new Article_Model();
The Standard PHP Library (SPL) offer a solution when working with different classes and libraries.

<?php 
    
    //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();  


Questions



Top Reference > Programming
0/0 (80)  
Not Logged