Composer has revolutionized package management in PHP. It upped the reusability game and helped PHP developers all over the world generate framework agnostic, fully shareable code. But few people ever go beyond the basics, so this post will cover some useful tips and tricks.
Global
Although it’s clearly defined in the documentation, Composer can (and in most cases should) be installed globally. Global installation means that instead of typing out
I think composer.lock should always be commited. Today’s techniques for deployment rerun composer install on each deploy which on a large composer.json (without composer.lock) file can result into a lot of time waiting.
Would be good to comment that composer require does not actually need you to specify the version and is also recommended that you let composer decide, as it also means you do not need to go look that up.
composer require package will automatically insert something like ~1.11 and will tell you. Adding the version only needs to be done in less frequent cases where you need to specify a version other then the latest.