Glossary · PHP & Backend

What is semantic versioning (SemVer)?

Short answer

Semantic versioning (SemVer) is a version-numbering scheme in the form MAJOR.MINOR.PATCH, where each number signals the kind of change: MAJOR for incompatible changes, MINOR for backwards-compatible features and PATCH for backwards-compatible fixes. Package managers like Composer and npm rely on it to update dependencies safely.

Reading a version number

Going from 2.4.1 to:

  • 2.4.2: a bug fix. Safe to update.
  • 2.5.0: new features; existing code keeps working.
  • 3.0.0: breaking changes. Read the upgrade guide.

Versions below 1.0.0 are considered unstable: any minor release may break things. Pre-releases look like 3.0.0-beta.2.

SemVer in Composer constraints

The caret ^2.4 allows any update up to, but not including, 3.0.0, trusting the library to follow SemVer. The tilde ~2.4.1 allows only patch updates up to 2.5.0. See exactly what any constraint allows with the Composer Version Constraint Checker.

Good habits

  • Commit composer.lock for applications so every environment installs the same versions.
  • Run tests in CI when updating, since not every library follows SemVer perfectly.
  • If you publish packages, keep a changelog and bump MAJOR for any change that can break users.

Published · Updated · By · All terms

Go deeper