Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Building Websites with PHP Dependency Management Introducing Composer

What is a dependency or package manager?

I am an absolute beginner when it comes to the terminology so can anyone explain it to me in a few sentences what a dependency or package manager is and why they are useful?

I am not asking for a detailed explanation, only something I can use as a basic guideline to search for articles and tutorials in this topic.

2 Answers

Jonathan Etienne
Jonathan Etienne
24,572 Points

Hi,

A dependency manager like composer for PHP, among others, is a tool that allows you to manage all of your libraries in a meaningful and logical manner. By dependencies, it means the libraries required to make this page work. It helps when your dealing with complex projects and in a team environment. It also allows you to keep track and update libraries faster and easier.

It also allows you to search libraries or package easier.

Sorry for the dumb question, but what is a PHP library? Is it like JQuery for JavaScript? And how is it different from a "package"? So if I get it right dependencies are like checklists (of which libraries my code needs to run properly)?

Jonathan Etienne
Jonathan Etienne
24,572 Points

All questions are good to ask. There is an extensive list of libraries which does include libraries like Jquery, and you can browse through all of them here: https://packagist.org/

They call it package, because many times you would have a collection of libraries that are package together, and you download that package rather than each individual library. As for dependency, many times a package will depend on another package, and the dependency manager can help solve that problem.

Each programming language have their own flavor of dependency manager. For instance, for Javascript Node.js you have NPM, for Ruby you have Bundler, for Python Pip, etc.

Kevin Korte
Kevin Korte
28,148 Points

Yes, a PHP library is like jQuery. For instance, I'm writing a custom app using that is using data from the Asana API to do things, and I decided to use PHP as it seemed to fit the clients current shared server the best.

So, I am using Composer to bring in the PHP library Asana wrote for developers like us to more easily take advantage for their API.

This is the package I'm using https://github.com/Asana/php-asana and Composer is managing the dependencies associated with it.

A dependency is another library that the one you are using requires. For instance, if you were using a jQuery plugin, jQuery would be it's dependency, since without jQuery, the plugin wouldn't work. The same thing is true with packages. When I had composer install the Asana PHP library, it also installed libraries called "Adoy" and "Nategood". I don't actually know what those two libraries do, and I don't really care, as I only interact with the Asana package, but Composer was smart enough to know my Asana package was going to need those other two libraries to work.

As applications scale, and more people get involved, it's a smart way to track external libraries your app is using, as you could pass someone the composer.json file, and they could run the composer install command, and they would have installed exactly the right amount of libraries, with the correct versions so they could code along.

I'm going to vote up Jonathan's response as it was very well.

Aaaah I think I am getting it now. But just to be on the safe side.

Library - A collection of already pre-written code to make my life easier so I don't have to write everything from scratch

Package - Collection of libraries that are built on each other or using each other one way or another

Dependencies - Managing how these libraries are related to each other and which ones are essential to run the code. For example library "A" is using code from library "B" so I need both if I want to use codes from library "A".

Hoorrraaay ^^. Thx guys. Seriously when you don't know the terminology all the tutorials look like they are written by aliens from an other planet. :)

Kevin Korte
Kevin Korte
28,148 Points

Yes it does, and just when you start to think you know most of the stuff about something, and new door opens and the learning adventure begins again. It's fun though.

Kevin, your answer is great, I had some questions about this topic but now I understand everything. Thanks

Kevin Korte
Kevin Korte
28,148 Points

Great! Glad it helped you. I appreciate the feedback