Search code examples
phpcomposer-phpversions

Composer version questions


I've got a few questions about composer:

1) Which operator should I better use in customer projects? ^ or ~ ?

2) When I specify:

"behat/behat": "~1.3"

does this mean that it will take all versions < 2.0, e.g. 1.3, 1.3.4, 1.3.7, 1.4, 1.5.7 ... or is it just counting the second digit (1.3, 1.4, 1.5, 1.6...)?

3) When I specifiy:

"behat/behat": "^1.3"

How is the behaviour here, regarding number 2).

Are there any other special cases, where I need to be careful when specifying the version number?


p.s I've already read the composer versions docs.


Solution

  • 1) Which operator should I better use in customer projects? ^ or ~ ?

    Prefer caret ^ over tilde ~ operator.

    2+3) What does it mean, when I specify: "behat/behat": "~1.3"

    ~1.3 is equivalent to >=1.3 <2.0.0.

    In brief:

    ~ sets a minimum version and allows last version digits to go up, while keeping BC safety.

    In detail:

    • it will fetch a version starting with the lowest version of the 1.3 series as lower boundary, probably 1.3.0
    • it will proceed with 1.3.*, 1.4.* and so on (all versions)
    • but it will remain below the upper version boundary of version 2.0.0

    The switch of an major version (here from 1.*.* to 2.*.*) indicates a possibly break in backward compatibility (see semantic versioning standard). The package manager will avoid to fetch breaking changes to keep your set of software dependencies working.

    Are there any other special cases, where I need to be careful when specifying the version number?

    There are special cases, for instance fetching "dev-master" and development dependencies with stability dev and other "special cases.

    But the question is too broad to provide a good answer. Ask again, when you run into trouble with "special cases".