Back to results for “Deployment”
PHP › Composer

How does semantic versioning work, and how do Composer's version constraint operators like caret and tilde let you control which updates are automatically accepted?

Intermediate

Answer

Semantic versioning structures a version number as major, minor, and patch, where major version increases indicate breaking changes, minor increases add backward compatible new features, and patch increases indicate backward compatible bug fixes, and Composer's caret operator allows updates that do not change the leftmost non zero digit, effectively accepting new minor and patch versions but not breaking major changes, while the tilde operator is slightly more restrictive, generally allowing only patch level updates within a specified minor version.
{
  "require": {
    "guzzlehttp/guzzle": "^7.0"
  }
}
Real-world example A project specifies its HTTP client library dependency using the caret operator, allowing Composer to automatically pull in new backward compatible feature releases and bug fixes over time, without ever accidentally upgrading to a new major version that might introduce breaking changes.

Common follow-ups: What is the difference between the caret and tilde version constraint operators specifically?;How do you pin a dependency to an exact, unchanging version?