0
0
PHPprogramming~20 mins

Composer require and dependency management in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Composer Dependency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of composer show after requiring a package?

You run composer require monolog/monolog in your PHP project. Then you run composer show monolog/monolog. What output will you see?

AOutputs only the version number of monolog/monolog
BDisplays package name, version, description, and dependencies of monolog/monolog
CLists all packages except monolog/monolog
DShows an error: Package monolog/monolog not found
Attempts:
2 left
💡 Hint

Think about what composer show does for a specific package.

Predict Output
intermediate
2:00remaining
What happens if you run composer require with a non-existent package?

You run composer require vendor/nonexistent-package in your project. What will happen?

AComposer adds the package to composer.json but does not install it
BComposer installs an empty package with no files
CComposer shows an error: Could not find package vendor/nonexistent-package
DComposer installs the latest stable version of a similar package automatically
Attempts:
2 left
💡 Hint

Composer only installs packages that exist in repositories it knows.

🔧 Debug
advanced
2:00remaining
Why does composer install not install new packages added manually to composer.json?

You manually add a new package to composer.json under require but running composer install does not install it. Why?

ABecause you must run <code>composer update</code> to install new packages after editing composer.json manually
BBecause the package is already installed globally and Composer ignores local installs
CBecause the package version constraint is invalid and Composer skips it silently
DBecause <code>composer update</code> only updates existing packages, not install new ones added manually
Attempts:
2 left
💡 Hint

Think about the difference between composer install and composer update.

📝 Syntax
advanced
2:00remaining
Which composer.json snippet correctly requires a package with a version constraint?

Choose the correct require section snippet to require guzzlehttp/guzzle version 7.0 or higher but less than 8.0.

A"require": { "guzzlehttp/guzzle": "^7.0" }
B"require": { "guzzlehttp/guzzle": ">=7.0,<8.0" }
C"require": { "guzzlehttp/guzzle": "7.*" }
D"require": { "guzzlehttp/guzzle": ">=7.0 <8.0" }
Attempts:
2 left
💡 Hint

Composer uses caret (^) for compatible version ranges.

🚀 Application
expert
2:00remaining
How to require a package only for development using composer?

You want to add phpunit/phpunit as a dependency only for development, not for production. Which command do you run?

Acomposer require phpunit/phpunit --optimize-autoloader
Bcomposer require phpunit/phpunit --update-no-dev
Ccomposer require phpunit/phpunit --no-dev
Dcomposer require phpunit/phpunit --dev
Attempts:
2 left
💡 Hint

Think about the flag that marks a package as development-only.