There is a difference between ~
and ^
in Composer, though it might not be immediately obvious in some cases. Let me clarify:
~
(tilde): Allows updates for the last digit specified.^
(caret): Allows updates for all minor versions within the same major version.
-
~7.3
:- Means
>=7.3.0
and<8.0.0
(allows updates to7.3.x
,7.4.x
,7.5.x
, etc.). - It happens to behave the same as
^7.3
in this case because both allow updates up to<8.0.0
.
- Means
-
^7.3
:- Means
>=7.3.0
and<8.0.0
(same range as~7.3
here).
- Means
The difference is clearer with more specific version constraints:
-
Example:
~7.3.1
vs.^7.3.1
~7.3.1
:>=7.3.1
and<7.4.0
(restricts updates to7.3.x
only).^7.3.1
:>=7.3.1
and<8.0.0
(allows updates to7.4.x
,7.5.x
, etc.).
-
Example:
~7.0
vs.^7.0
~7.0
:>=7.0.0
and<8.0.0
.^7.0
:>=7.0.0
and<8.0.0
.- In this case, they behave the same again.
- For
~7.3
and^7.3
, there is no difference because both allow updates from7.3.0
up to<8.0.0
. - However,
~
is stricter when you specify patch versions (e.g.,~7.3.1
allows less than^7.3.1
).