What is Autoloading in CodeIgniter 4?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid CodeIgniter basics — a prerequisite for any developer role.

Answer

CodeIgniter 4 uses PSR-4 autoloading via Composer for class loading. Define your app namespace in composer.json: "App\\": "app/" — then any class in app/ is automatically available as App\Controllers\UserController. CI4's own Config/Autoload.php configures: $psr4 (namespace to directory mapping), $classmap (explicit class path mapping), and $files (files to always include). Helpers and libraries specified in $helpers and $libraries are autoloaded globally. Run composer dump-autoload to regenerate the classmap. The CodeIgniter class locator also supports loading classes from multiple namespaces (allowing modules to override core classes). This modern autoloading approach replaced CI3's manual $this->load->library() pattern.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex CodeIgniter answers easy to follow.