Explain how Autoloading works in modern PHP. Why is it preferred over manual require or include?

Last updated 15 June 2026

  • 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-4 autoloader maps namespace prefixes to directories (App\Models\User to src/Models/User.php), so you include only vendor/autoload.php.

  • It beats manual require: lazy loading saves memory, no fragile include lists, and composer dump-autoload -o builds a fast classmap for production.

  • https://www.reddit.com/r/PHP/comments/1p6bprs/why_dont_major_companies_invest_in_phps_evolution/
  • https://www.reddit.com/r/PHP/comments/1bp7tfh/what_is_the_future_of_php/
All PHP interview questions