In PHP we’ve had a lousy culture of code-sharing. Because depending on code from others as been tricky, every major PHP application or framework has practically had to reimplement the whole world. Only some tools, like PHPUnit, have managed to break over this barrier and become de-facto standards across project boundaries. But for the rest: just write it yourself.

Managing dependencies between pieces of software, in PHP, hasn’t always
been a relief: we had PEAR and PECL1
with their workflows and problems while, in other ecosystems, the
solution to this problem has been solved in better ways, like
NodeJS’s NPM.

Composer

Composer is the nifty missing brick in managing PHP dependencies:
inspired to what’s hot in Ruby’s and NodeJS’s ecosystems, it is a
simple but powerful packaging system specifically written for PHP.

Born and mantained from a few personalities
of the Symfony2 community, it’s really easy to use and install.

First of all, go to the root directory of your project and
download composer:

this is basically awesome because it lets you specify the
autoloading standard used for your library (I strongly suggest
you to follow the PSR-0 convention):
in the example we see that our NutsAPI namespace will be
autoloaded in the src directory.

You should not ignore the [composer.lock] file in git.In fact you should commit it whenever it is changed.Users of your project or other developers can then run “composer install” to install exactly the versions you had in your lock file, rather than installing versions based on composer.json and potentially ending up with a slightly newer dependency which could result in problems, since you didn’t test with that particular version.