What are the core principles behind Semantic versioning?

Semantic versioning, often abbreviated as SemVer, is a versioning scheme for software that aims to convey meaning about the underlying changes with each new release. The core principles of Semantic versioning are defined in the format of MAJOR.MINOR.PATCH, where:

  • MAJOR version: Incremented when making incompatible API changes.
  • MINOR version: Incremented when adding functionality in a backwards-compatible manner.
  • PATCH version: Incremented when making backwards-compatible bug fixes.

Following these principles helps developers understand the level of changes made and the impact they might have on their applications.

// Example of semantic versioning function updateVersion($currentVersion, $type) { list($major, $minor, $patch) = explode('.', $currentVersion); switch($type) { case 'major': $major++; $minor = 0; $patch = 0; break; case 'minor': $minor++; $patch = 0; break; case 'patch': $patch++; break; } return "$major.$minor.$patch"; } // Usage echo updateVersion("1.4.2", "minor"); // Output: 1.5.0

semantic versioning SemVer software versioning MAJOR.MINOR.PATCH version control