- Basic Constraints
- Next Significant Release Operators
- Test version constraints
You can specify the exact version of a package. This will tell Composer to install this version and this version only. If other dependencies require a different version, the solver will ultimately fail and abort any install or update procedures.
By using comparison operators you can specify ranges of valid versions. Valid
You can define multiple ranges. Ranges separated by a space (
,) will be treated as a logical AND. A double pipe (
will be treated as a logical OR. AND has higher precedence than OR.
Note: Be careful when using unbounded ranges as you might end up unexpectedly installing versions that break backwards compatibility. Consider using the caret operator instead for safety.
>=1.0 <1.1 || >=1.2
Inclusive set of versions. Partial versions on the right include are completed
with a wildcard. For example
1.0 - 2.0 is equivalent to
>=1.0.0 <2.1 as the
2.0.*. On the other hand
1.0.0 - 2.1.0 is equivalent to
1.0 - 2.0
You can specify a pattern with a
1.0.* is the equivalent of
Next Significant Release Operators#
~ operator is best explained by example:
~1.2 is equivalent to
>=1.2 <2.0.0, while
~1.2.3 is equivalent to
>=1.2.3 <1.3.0. As you can see
it is mostly useful for projects respecting semantic
versioning. A common usage would be to mark the minimum
minor version you depend on, like
~1.2 (which allows anything up to, but not
including, 2.0). Since in theory there should be no backwards compatibility
breaks until 2.0, that works well. Another way of looking at it is that using
~ specifies a minimum version, but allows the last digit specified to go up.
2.0-beta.1is strictly before
2.0, a version constraint like
~1.2would not install it. As said above
~1.2only means the
.2can change but the
1.part is fixed.
~operator has an exception on its behavior for the major release number. This means for example that
~1is the same as
~1.0as it will not allow the major number to increase trying to keep backwards compatibility.
^ operator behaves very similarly but it sticks closer to semantic
versioning, and will always allow non-breaking updates. For example
is equivalent to
>=1.2.3 <2.0.0 as none of the releases until 2.0 should
break backwards compatibility. For pre-1.0 versions it also acts with safety
in mind and treats
This is the recommended operator for maximum interoperability when writing library code.
If you are using a constraint that does not explicitly define a stability,
Composer will default internally to
-stable, depending on the
operator(s) used. This happens transparently.
If you wish to explicitly consider only the stable release in the comparison,
add the suffix
To allow various stabilities without enforcing them at the constraint level
however, you may use stability-flags like
@dev) to let composer know that a given package
can be installed in a different stability than your default
Test version constraints#
You can test version constraints using semver.mwl.be.
Fill in a package name and it will autofill the default version constraint
which Composer would add to your
composer.json file. You can adjust the
version constraint and the tool will highlight all releases that match.
Found a typo? Something is wrong in this documentation? Just fork and edit it!