0
0
PHPprogramming~5 mins

Composer require and dependency management in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the composer require command do?
It adds a new package to your project and updates the composer.json and composer.lock files automatically.
Click to reveal answer
beginner
What is the purpose of the composer.lock file?
It locks the exact versions of all installed packages to ensure consistent installs across different environments.
Click to reveal answer
intermediate
How does Composer handle version conflicts between packages?
Composer tries to find a set of package versions that satisfy all version constraints. If it can't, it shows an error and stops the installation.
Click to reveal answer
beginner
What is the difference between require and require-dev in Composer?
require is for packages needed in production, while require-dev is for packages only needed during development, like testing tools.
Click to reveal answer
beginner
Why should you commit composer.lock to version control?
Committing composer.lock ensures everyone uses the same package versions, avoiding unexpected bugs caused by different dependencies.
Click to reveal answer
What happens when you run composer require monolog/monolog?
AComposer updates PHP version.
BOnly <code>composer.json</code> is updated, no packages installed.
CMonolog package is added and <code>composer.json</code> and <code>composer.lock</code> are updated.
DComposer removes all existing packages.
Which file ensures consistent package versions across different machines?
A<code>vendor/composer</code>
B<code>composer.json</code>
C<code>autoload.php</code>
D<code>composer.lock</code>
If two packages require conflicting versions of the same dependency, what does Composer do?
AShows an error and stops installation.
BIgnores the conflict and installs both versions.
CAutomatically picks the newest version.
DRemoves one of the conflicting packages.
Which command installs packages listed in require-dev?
A<code>composer install --no-dev</code>
B<code>composer install</code>
C<code>composer update --no-dev</code>
D<code>composer dump-autoload</code>
Why is it important to commit composer.lock to your project repository?
ATo ensure all developers use the same package versions.
BTo speed up Composer commands.
CTo avoid installing any packages.
DTo update PHP automatically.
Explain how composer require helps manage dependencies in a PHP project.
Think about what files change and what happens to the package.
You got /4 concepts.
    Describe the role of composer.lock and why it is important to commit it to version control.
    Consider what happens if different developers have different versions.
    You got /4 concepts.