Dependency Management in PHP

dependency-management

Since my expertise is in PHP languange, so I will discuss dependency management in PHP. However most of the concept should be applicable to other major programming languages.

To understand dependency management, we have to first look at the PHP programming language. It has grown to have a lot framework and libraries that most projects do not have to start from zero. A developer can simply pick up relevant libraries and framework and start working his/her project objectives from there. There is no need to create everything from scratch. What a wonderful world!

However, there is one problem, since the libraries and framework are also evolving, it becomes a problem of its own. Not all libraries and framework is 100% backward compatible. Meaning, not every new version of the libraries and framework is still compatible with older versions. So, it is possible that upgrading from an old framework / libraries will break the project.

Hunting down the right library or framework can also be a difficult tasks, with thousands of choices and options.

This is where dependency management comes in. The dependency manager application will take care of the compatibility for us. It also serves as a repository, where we can search for a good library / framework that is a great match for our project.

The concept of dependency management itself is not new, it is used successfully in Linux, first with RedHat RPM and also with Debian Package Management with its popular Ubuntu Linux distro.

Basically when you install Linux, or Ubuntu in this case, you will have a Software Center where you can search for any software that you like and install it from the Software Center. Try it yourself by downloading any Debian based Distro.

Now, this concept, is also used in programming languages. In PHP, there was PEAR and PECL which for a long time is the defacto Dependency Manager for PHP.

But now, there is a new dependency manager called Composer that is very popular.

Both serves its own purposes.

Currently there are two major package management systems for PHP – Composer and PEAR. Which one is right for you? The answer is both.

  • Use Composer when managing dependencies for a single project.
  • Use PEAR when managing dependencies for PHP as a whole on your system.

In general, Composer packages will be available only in the projects that you explicitly specify whereas a PEAR package would be available to all of your PHP projects. While PEAR might sound like the easier approach at first glance, there are advantages to using a project-by-project approach to your dependencies.

Source: PHP The Right Way

Since both have its own purposes, I will discuss them separately. Now, which one will I talk about tomorrow ?