PHPackages                             composer/semver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. composer/semver

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

composer/semver
===============

Version comparison library that offers utilities, version constraint parsing and validation.

3.4.4(9mo ago)3.3k489.6M↑10.4%7620MITPHPPHP ^5.3.2 || ^7.0 || ^8.0CI passing

Since Jul 23Pushed 1mo ago13 watchersCompare

[ Source](https://github.com/composer/semver)[ Packagist](https://packagist.org/packages/composer/semver)[ Fund](https://packagist.com)[ GitHub Sponsors](https://github.com/composer)[ RSS](/packages/composer-semver/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (39)Used By (20)

composer/semver
===============

[](#composersemver)

Version comparison library that offers utilities, version constraint parsing and validation.

It follows semver (semantic versioning) where possible but is also constrained by `version_compare` and backwards compatibility and as such cannot implement semver strictly.

Originally written as part of [composer/composer](https://github.com/composer/composer), now extracted and made available as a stand-alone library.

[![Continuous Integration](https://github.com/composer/semver/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/composer/semver/actions/workflows/continuous-integration.yml)[![PHP Lint](https://github.com/composer/semver/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/composer/semver/actions/workflows/lint.yml)[![PHPStan](https://github.com/composer/semver/actions/workflows/phpstan.yml/badge.svg?branch=main)](https://github.com/composer/semver/actions/workflows/phpstan.yml)

Installation
------------

[](#installation)

Install the latest version with:

```
composer require composer/semver
```

Requirements
------------

[](#requirements)

- PHP 5.3.2 is required but using the latest version of PHP is highly recommended.

Version Comparison
------------------

[](#version-comparison)

For details on how versions are compared, refer to the [Versions](https://getcomposer.org/doc/articles/versions.md)article in the documentation section of the [getcomposer.org](https://getcomposer.org) website.

Basic usage
-----------

[](#basic-usage)

### Validation / Normalization

[](#validation--normalization)

The [`Composer\Semver\VersionParser`](https://github.com/composer/semver/blob/main/src/VersionParser.php)class provides the following methods for parsing, normalizing and validating versions and constraints.

Numeric versions are normalized to a 4 component versions (e.g. `1.2.3` is normalized to `1.2.3.0`) for internal consistency and compatibility with `version_compare`. Normalized versions are used for constraints internally but should not be shown to end users.

For versions:

- isValid($version)
- normalize($version, $fullVersion = null)
- normalizeBranch($name)
- normalizeDefaultBranch($name)

For constraints:

- parseConstraints($constraints)

For stabilities:

- parseStability($version)
- normalizeStability($stability)

### Comparison

[](#comparison)

The [`Composer\Semver\Comparator`](https://github.com/composer/semver/blob/main/src/Comparator.php) class provides the following methods for comparing versions:

- greaterThan($v1, $v2)
- greaterThanOrEqualTo($v1, $v2)
- lessThan($v1, $v2)
- lessThanOrEqualTo($v1, $v2)
- equalTo($v1, $v2)
- notEqualTo($v1, $v2)

Each function takes two version strings as arguments and returns a boolean. For example:

```
use Composer\Semver\Comparator;

Comparator::greaterThan('1.25.0', '1.24.0'); // 1.25.0 > 1.24.0
```

### Semver

[](#semver)

The [`Composer\Semver\Semver`](https://github.com/composer/semver/blob/main/src/Semver.php) class provides the following methods:

- satisfies($version, $constraints)
- satisfiedBy(array $versions, $constraint)
- sort($versions)
- rsort($versions)

### Intervals

[](#intervals)

The [`Composer\Semver\Intervals`](https://github.com/composer/semver/blob/main/src/Intervals.php) static class provides a few utilities to work with complex constraints or read version intervals from a constraint:

```
use Composer\Semver\Intervals;

// Checks whether $candidate is a subset of $constraint
Intervals::isSubsetOf(ConstraintInterface $candidate, ConstraintInterface $constraint);

// Checks whether $a and $b have any intersection, equivalent to $a->matches($b)
Intervals::haveIntersections(ConstraintInterface $a, ConstraintInterface $b);

// Optimizes a complex multi constraint by merging all intervals down to the smallest
// possible multi constraint. The drawbacks are this is not very fast, and the resulting
// multi constraint will have no human readable prettyConstraint configured on it
Intervals::compactConstraint(ConstraintInterface $constraint);

// Creates an array of numeric intervals and branch constraints representing a given constraint
Intervals::get(ConstraintInterface $constraint);

// Clears the memoization cache when you are done processing constraints
Intervals::clear()
```

See the class docblocks for more details.

License
-------

[](#license)

composer/semver is licensed under the MIT License, see the LICENSE file for details.

###  Health Score

77

—

ExcellentBetter than 100% of packages

Maintenance77

Regular maintenance activity

Popularity83

Widely adopted with strong download metrics

Community56

Growing community involvement

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 56.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~99 days

Recently: every ~180 days

Total

38

Last Release

271d ago

Major Versions

1.5.2 → 3.0.12020-09-08

1.6.0 → 3.1.02020-09-08

1.7.0 → 3.2.02020-09-09

1.7.1 → 3.2.12020-09-27

1.7.2 → 3.2.52021-05-24

PHP version history (3 changes)0.1.0PHP &gt;=5.3.2

1.1.0PHP ^5.3.2 || ^7.0

3.0.0PHP ^5.3.2 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b69782e1d7f426ef78f61d159c466a536372eff931f13981ac578fa3f4649352?d=identicon)[Seldaek](/maintainers/Seldaek)

![](https://www.gravatar.com/avatar/7b53fd135df4732d40488c0394fae263e128283081f2b833e3dc0a780b4b900d?d=identicon)[naderman](/maintainers/naderman)

![](https://www.gravatar.com/avatar/b63efaf06b867a66bc5426b30d1405152ee1b21740a0dd1b14b5122cf58d779d?d=identicon)[alcohol](/maintainers/alcohol)

---

Top Contributors

[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (269 commits)")[![alcohol](https://avatars.githubusercontent.com/u/21414?v=4)](https://github.com/alcohol "alcohol (75 commits)")[![naderman](https://avatars.githubusercontent.com/u/154844?v=4)](https://github.com/naderman "naderman (40 commits)")[![Toflar](https://avatars.githubusercontent.com/u/481937?v=4)](https://github.com/Toflar "Toflar (10 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (9 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (8 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (7 commits)")[![jderusse](https://avatars.githubusercontent.com/u/578547?v=4)](https://github.com/jderusse "jderusse (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (5 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (5 commits)")[![aadmathijssen](https://avatars.githubusercontent.com/u/3796971?v=4)](https://github.com/aadmathijssen "aadmathijssen (4 commits)")[![adragus-inviqa](https://avatars.githubusercontent.com/u/13104649?v=4)](https://github.com/adragus-inviqa "adragus-inviqa (4 commits)")[![zczapran](https://avatars.githubusercontent.com/u/586247?v=4)](https://github.com/zczapran "zczapran (4 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (3 commits)")[![clxmstaab](https://avatars.githubusercontent.com/u/47448731?v=4)](https://github.com/clxmstaab "clxmstaab (3 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (3 commits)")[![simensen](https://avatars.githubusercontent.com/u/191200?v=4)](https://github.com/simensen "simensen (2 commits)")[![TysonAndre](https://avatars.githubusercontent.com/u/1904430?v=4)](https://github.com/TysonAndre "TysonAndre (2 commits)")[![francoispluchino](https://avatars.githubusercontent.com/u/567393?v=4)](https://github.com/francoispluchino "francoispluchino (2 commits)")

---

Tags

validationsemverversioningsemantic

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/composer-semver/health.svg)

```
[![Health](https://phpackages.com/badges/composer-semver/health.svg)](https://phpackages.com/packages/composer-semver)
```

###  Alternatives

[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[z4kn4fein/php-semver

Semantic Versioning library for PHP. It implements the full semantic version 2.0.0 specification and provides ability to parse, compare, and increment semantic versions along with validation against constraints.

251.5M17](/packages/z4kn4fein-php-semver)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[nikolaposa/version

Value Object that represents a SemVer-compliant version number.

1406.4M16](/packages/nikolaposa-version)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
