Search code examples
symfonycomposer-php

How does composer handle multiple versions of the same package?


This may (should) have been asked before somewhere but I can't seem to find an answer. If someone provides a link I can delete this post!:

Just trying to get my head around some of composer's (probably applies to other package managers too) functionality.

Basically I just want to know what composer does in the following scenarios:

1.

My main project has a dependency:

"guzzlehttp/guzzle": "5.0.*",

My external bundle has a dependency on

"guzzlehttp/guzzle": "5.0.*",

Does composer install guzzlehttp/guzzle one time because it knows it only needs it once?

2. Same scenario but in the future if someone updates the main project to use:

"guzzlehttp/guzzle": "6.0.*",

Will composer now install 2 versions of guzzle (5 and 6) (I presume this is what it should do), or will it take the highest version (i.e. 6)? Also if there are 2 versions will this cause any conflicts because namespaces might be the same?

Thanks


Solution

  • To question 1

    Yes Composer can only install one version of each extension/package.

    To question 2

    Because of answer 1: Composer would consider your main project and the external package as incompatible.

    In this case you could

    • stay with version 5 at your main project too.
    • ask the external package owner to upgrade to version 6 too if it's compatible to.
    • fork the external package and make it compatible to version 6 yourself