Laravel

Composer & Autoloading

Composer basics, composer.json, autoloading PSR-4, dependency management, semantic versioning, scripts, security audit

18 interview questionsยท
Junior
1

What is Composer in the PHP ecosystem?

Answer

Composer is the standard dependency manager for PHP, allowing developers to declare and install libraries that a project depends on. It automatically manages compatible versions and downloads packages from Packagist. Unlike PEAR (legacy manager), Composer installs dependencies per project rather than globally.

2

Which file contains the list of dependencies for a PHP project managed by Composer?

Answer

The composer.json file is the project manifest that declares all dependencies, custom scripts, autoloading configuration, and project metadata. This file is versioned in Git and edited manually. The composer.lock is automatically generated and should never be manually edited.

3

Which Composer command installs project dependencies without updating composer.lock?

Answer

The composer install command reads the composer.lock file (or composer.json if .lock is missing) and installs exactly the specified versions, ensuring identical installations across all environments. In production or when cloning a project, always use install to reproduce the exact environment. The update command upgrades versions and modifies composer.lock.

4

What is the difference between require and require-dev in composer.json?

5

What is the role of the composer.lock file?

+15 interview questions

Master Laravel for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free