Composer for PHPs
Composer is the dependency manager for PHP. A composer.json file lists the packages a project needs, composer install downloads them into vendor and records exact versions in composer.lock. It also generates the autoloader and follows community standards such as PSR-12 for code style and PSR-4 for loading.
Stage: Object-Oriented PHP · Part of the PHP roadmap · Last reviewed 19 November 2026
What to learn in Composer
- Create composer.json and install a package from Packagist
- Explain semantic version constraints like ^2.1 and ~2.1
- Commit composer.lock so every machine installs the same versions
- Configure PSR-4 autoloading for your own namespace
- Run a code style checker to enforce PSR-12
Composer interview questions
What is the difference between composer install and composer update?
install reads composer.lock and installs the exact locked versions, giving repeatable builds. update ignores the lock, finds the newest versions allowed by composer.json, and rewrites the lock file. Use install in deployment and update deliberately.
Why commit composer.lock for an application?
The lock file records the exact version of every dependency, including indirect ones. Committing it means teammates and servers install identical code, so a new upstream release cannot silently break the app between deploys.
Where Composer fits in the PHP roadmap
Composer belongs to the Object-Oriented PHP stage (beginner level), which takes about 19 hours. Structure code.