PHPackages                             semver/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. semver/semver

AbandonedArchivedLibrary

semver/semver
=============

The semver parser for PHP

1.1.0(9y ago)324.2k↑87.5%MITPHPPHP &gt;=7.0.0

Since May 26Pushed 9y ago1 watchersCompare

[ Source](https://github.com/git-pull-request/php-semver)[ Packagist](https://packagist.org/packages/semver/semver)[ Docs](http://semver.org)[ RSS](/packages/semver-semver/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

PHP7+ SemVer
============

[](#php7-semver)

PHP implementation of the Semantic Versioning 2.0 documented on [semver.org](http://semver.org)

[![Build Status](https://camo.githubusercontent.com/f1e8eccb75e0416e49c493b882f7237800584a6f254b50aadb0f453ee946d0eb/68747470733a2f2f7472617669732d63692e6f72672f6769742d70756c6c2d726571756573742f7068702d73656d7665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/git-pull-request/php-semver) [![Coverage Status](https://camo.githubusercontent.com/ec0c78f55dc8894a8dd6530fc62de6569d9c6ca070d20230ee9748b196645133/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6769742d70756c6c2d726571756573742f7068702d73656d7665722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/git-pull-request/php-semver?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/eb2951332b2e0bb0e372e69ca1e95ca6503e267e8e5ad0dc5331db608e36b62a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6769742d70756c6c2d726571756573742f7068702d73656d7665722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/git-pull-request/php-semver/?branch=master)

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

[](#installation)

Install the latest version with

```
$ composer require semver/semver
```

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

[](#requirements)

This library is standalone so you don't have to worry about dependencies.
The only requirement is to use **PHP 7**

Usage
-----

[](#usage)

### Create a Version

[](#create-a-version)

**from decomposed elements**

```
use SemVer\SemVer\Version;

$version = new Version(1, 2, 3);
$version = new Version(1, 2, 3, '', 'exp.sha.5114f85');
$version = new Version(1, 2, 3, 'rc.1', 'exp.sha.5114f85');
```

**from a string**

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.2.3');
$version = Version::fromString('1.2.3+exp.sha.5114f85');
$version = Version::fromString('1.2.3-rc.1+exp.sha.5114f85');
```

### Update to next version

[](#update-to-next-version)

It will always create a new Version, leaving the current as it is.

**update the major version**

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.2.3');
$nextVersion = $version->major();

var_dump($nextVersion->isEquals(new Version('2.0.0')); // true
```

Special case: when there is a pre-release and both minor and patch version are equals to 0, the next major version is the actual version without the pre-release

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.0.0-rc.1');
$nextVersion = $version->major();

var_dump($nextVersion->isEquals(new Version('1.0.0')); // true
```

**update the minor version**

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.2.3');
$nextVersion = $version->minor();

var_dump($nextVersion->isEquals(new Version('1.3.0')); // true
```

Special case: when there is a pre-release and the patch version is equal to 0, the next minor version is the actual version without the pre-release

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.1.0-rc.1');
$nextVersion = $version->minor();

var_dump($nextVersion->isEquals(new Version('1.1.0')); // true
```

**update the patch version**

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.2.3-rc.1');
$nextVersion = $version->patch();

var_dump($nextVersion->isEquals(new Version('1.2.3')); // true
```

Special case: when there is a pre-release, the next major version is the actual version without the pre-release

```
use SemVer\SemVer\Version;

$version = Version::fromString('1.0.0-rc.1');
$nextVersion = $version->patch();

var_dump($nextVersion->isEquals(new Version('1.0.0')); // true
```

### Compare two versions

[](#compare-two-versions)

```
use SemVer\SemVer\Version;
use SemVer\SemVer\VersionComparator;

$version1 = Version::fromString('1.2.3');
$version2 = Version::fromString('1.2.3-rc.1+exp.sha.5114f85');
var_dump(VersionComparator::compare($version1, $version2)); // 1
var_dump($version1->equals($version2)); // false
var_dump($version1->greaterThan($version2)); // true
var_dump($version1->greaterThanOrEqual($version2)); // true
var_dump($version1->lessThan($version2)); // false
var_dump($version1->lessThanOrEqual($version2)); // false
```

### Sort an array of Versions

[](#sort-an-array-of-versions)

```
use SemVer\SemVer\Version;

$versions = [
    Version::fromString('2.0.0'),
    Version::fromString('1.2.3'),
    Version::fromString('1.3.3'),
    Version::fromString('1.3.3-alpha.10'),
    Version::fromString('1.3.3-alpha.2'),
    Version::fromString('1.2.3-rc.1+exp.sha.5114f85'),
];
var_dump(VersionSorter::sort($versions));
// Result:
// [
//    Version::fromString('1.2.3-rc.1+exp.sha.5114f85'),
//    Version::fromString('1.2.3'),
//    Version::fromString('1.3.3-alpha.2'),
//    Version::fromString('1.3.3-alpha.10'),
//    Version::fromString('1.3.3'),
//    Version::fromString('2.0.0'),
// ];
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

6

Last Release

3643d ago

Major Versions

0.3.1 → 1.0.02016-05-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/5cc2f661073d68100db53e02e0892a69076f0b44bc0ced487b043c6aff28ad0c?d=identicon)[JulienDufresne](/maintainers/JulienDufresne)

---

Top Contributors

[![juliendufresne](https://avatars.githubusercontent.com/u/1397529?v=4)](https://github.com/juliendufresne "juliendufresne (7 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

PHPackages © 2026

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