What is the difference between PEAR and Composer?
PEAR is used to install a PHP software package and Composer is used for the same thing. I believe Composer handles dependencies better but is that the only difference? Can anybody explain the difference between these two package managers and tell me when to use which?
It might be a bit soon to regard PEAR as deprecated but I don't believe it will take long before it is. Composer is thriving and mature with a lot of packages and and active development. Therefore it might be better to use Composer as the standard for package management tool in PHP.
Using PEAR is more cumbersome for package maintainers. Therefore a lot of the code on PEAR is outdated. A developer needs to get it packages 'PEAR-reviewed' before it might get published on PEAR, so few packages are available compared to the number of packages available in Composer. Also, there is no way to install a package in PEAR for one single project. All packages are installed globally. With Composer you can install packages one a per-project basis or globally. Well and then there is the lack of dependency management in PEAR, which frankly should be the one thing a package manager does well.
One thing you can do with PEAR and not with Composer is installing PECL extensions. There is however pickle which uses Composer and lets you define native PHP extentions dependencies in your composer.json
file. The pickle project is momentarily undergoing quite some development and should not yet be considered mature.
This blog post by Fabien Potencier might be a bit opinionated, but I think it is quite right. If you have an option, choose Composer so PEAR can die in peace. Even when you ask the PEAR maintainers most will tell you that Composer is the way forward, although some might still have their hopes for Pyrus. (This was intended to be PEAR improved, but got kindof buried under the exploding popularity of Composer.)
By the way, you can use Composer to install PEAR packages as well, see the Composer documentation.
See also:
[1] Informative slide deck about PHP package management