Explain how Autoloading works in modern PHP. Why is it preferred over manual require or include?
Last updated
Autoloading loads a class file on demand the first time an undefined class is used, via callbacks registered with
spl_autoload_register().Composer's
PSR-4autoloader maps namespace prefixes to directories (App\Models\Usertosrc/Models/User.php), so you include onlyvendor/autoload.php.It beats manual
require: lazy loading saves memory, no fragile include lists, andcomposer dump-autoload -obuilds a fast classmap for production.