Composer for PHP Flashcards
Q: What is Composer in PHP?
A: A dependency manager for PHP projects.
Q: How do you install Composer globally?
php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
php composer-setup.php
mv composer.phar /usr/local/bin/composer
Q: How do you verify Composer is installed?
A: Run composer –version.
Q: What is the default file used by Composer to manage dependencies?
A: composer.json.
Q: What command creates a new composer.json file?
A: composer init.
Q: How do you install a package with Composer?
A: composer require vendor/package-name.
Q: What command installs all dependencies listed in composer.json?
A: composer install.
Q: How do you update all dependencies to their latest versions?
A: composer update.
Q: How do you install a specific version of a package?
A: composer require vendor/package-name:^1.2.
Q: How do you install dependencies without autoloading?
A: composer install –no-autoloader.
Q: What is the purpose of the require section in composer.json?
A: Specifies the project’s dependencies.
Q: What is the require-dev section used for?
A: Lists dependencies needed only for development.
Q: How do you specify a PHP version requirement in composer.json?
“require”: {
“php”: “>=7.4”
}
Q: What is the autoload section in composer.json for?
A: Defines how classes and files are loaded automatically.
Q: What is the scripts section in composer.json?
A: Defines custom scripts that can be executed with Composer commands.
Q: What is Composer’s autoloader file?
A: vendor/autoload.php.