phpautoload

What is autoload in php?


what is autoload in PHP?


Solution

  • The blog post “PHP AutoLoad Best Practices” will be of help to you about the usage of autoload.

    It’s a magic function that helps you include / require files using the class name.

    function __autoload($class_name) 
    {
        require_once $DOCUMENT_ROOT . "/classes/" . $class_name . ".php";
    }
    

    It’s deprecated in PHP 7.2.0, and now spl_autoload_register is recommended for this purpose.