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

ActiveLibrary

phlak/semver
============

Semantic versioning helper library

6.1.1(11mo ago)1821.6M—9.4%17[1 PRs](https://github.com/PHLAK/SemVer/pulls)20MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4CI passing

Since Jun 24Pushed 5mo ago6 watchersCompare

[ Source](https://github.com/PHLAK/SemVer)[ Packagist](https://packagist.org/packages/phlak/semver)[ GitHub Sponsors](https://github.com/sponsors/PHLAK)[ Fund](https://paypal.me/ChrisKankiewicz)[ RSS](/packages/phlak-semver/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (20)

SemVer
======

[](#semver)

 [![SemVer](semver.png)](semver.png)

 [Semantic versioning](http://semver.org) helper library • Created by [Chris Kankiewicz](https://www.ChrisKankiewicz.com) ([@phlak.dev](https://bsky.app/profile/phlak.dev))

 [![Join our Community](https://camo.githubusercontent.com/073a08ec4c3c801a8e24c53184d95a6562d74582854cb46320bcd76ef48ea543/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e5f7468652d436f6d6d756e6974792d3762313666662e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/PHLAK/SemVer/discussions) [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/d4ace6f091a1a5959717d9e55a2af1f6e46d49d425510788600d3c0fa56eb391/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f50484c414b2f53656d5665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/SemVer) [![Total Downloads](https://camo.githubusercontent.com/5bfe0829ba5cbc15df6860dffd5ce1d0f09f85529314e4ed2308c2de7bc0fc2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f50484c414b2f53656d5665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/SemVer) [![License](https://camo.githubusercontent.com/6622d1658b3c27cc0ff55b22e7c59b97383b67dde8b144db9e4f871a4bf75a3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f50484c414b2f53656d5665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/SemVer) [![Tests Status](https://camo.githubusercontent.com/30a11f6984cc4352cf5a22b02d9e835fdd11110463d21abb72ff170901e4f6aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50484c414b2f53656d5665722f746573742d73756974652e79616d6c3f7374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/PHLAK/SemVer/actions)

---

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

[](#requirements)

- [PHP](https://php.net) &gt;= 8.1

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

[](#installation)

```
composer require phlak/semver
```

Initializing
------------

[](#initializing)

```
use PHLAK\SemVer;

$version = new SemVer\Version(); // Initilializes to '0.1.0'
```

Or initialize with a custom version by passing a version string on creation. Accepts any valid semantic version string with or without a preceding `v`.

```
$version = new SemVer\Version('v1.2.3-alpha.5+sha.8d31ff4');
```

Or parse an incomple version string with the static `Version::parse()` constructor.

```
$version = SemVer\Version::parse('v1')   // Initializes to '1.0.0'
$version = SemVer\Version::parse('v1.2') // Initializes to '1.2.0'
```

Usage
-----

[](#usage)

#### Retrieve the version or individual values

[](#retrieve-the-version-or-individual-values)

```
$version = new SemVer\Version('v1.2.3-beta.4+007');

echo $version;             // '1.2.3-beta.4+007'
echo $version->major;      // 1
echo $version->minor;      // 2
echo $version->patch;      // 3
echo $version->preRelease; // 'beta.4'
echo $version->build;      // '007'
```

#### Increment the version

[](#increment-the-version)

```
$version = new SemVer\Version('v1.2.3');

$version->incrementMajor();      // v1.2.3 -> v2.0.0
$version->incrementMinor();      // v1.2.3 -> v1.3.0
$version->incrementPatch();      // v1.2.3 -> v1.2.4
$version->incrementPreRelease(); // v1.2.3-alpha.5 -> v1.2.3-alpha.6
```

#### Set (override) the version or individual values

[](#set-override-the-version-or-individual-values)

```
$version = new SemVer\Version();

$version->setVersion('v1.2.3');  // v1.2.3
$version->setMajor(3);           // v1.2.3 -> v3.0.0
$version->setMinor(5);           // v1.2.3 -> v1.5.0
$version->setPatch(7);           // v1.2.3 -> 1.2.7
$version->setPreRelease('rc.2'); // v1.2.3 -> v1.2.3-rc.2
$version->setBuild('007');       // v1.2.3 -> v1.2.3+007
```

#### Clear pre-release / build values

[](#clear-pre-release--build-values)

```
$version->setPreRelease(null); // v1.2.3-rc.2 -> v1.2.3
$version->setBuild(null);      // v1.2.3+007 -> v1.2.3
```

#### Check for pre-release / build values

[](#check-for-pre-release--build-values)

```
$version->isPreRelease();
$version->hasBuild();
```

#### Compare two SemVer objects

[](#compare-two-semver-objects)

```
$version1 = new SemVer\Version('v1.2.3');
$version2 = new SemVer\Version('v3.2.1');

$version1->gt($version2);  // false
$version1->lt($version2);  // true
$version1->eq($version2);  // false
$version1->neq($version2); // true
$version1->gte($version2); // false
$version1->lte($version2); // true
```

##### Limit comparison to the major version only

[](#limit-comparison-to-the-major-version-only)

Ignores the minor, patch and pre-release versions completely

```
$version1 = new SemVer\Version('v1.2.3-alpha.4');
$version2 = new SemVer\Version('v1.3.4-alpha.5');

$version1->gt($version2, Compare::MAJOR);  // false
$version1->lt($version2, Compare::MAJOR);  // false
$version1->eq($version2, Compare::MAJOR);  // true
$version1->neq($version2, Compare::MAJOR); // false
$version1->gte($version2, Compare::MAJOR); // true
$version1->lte($version2, Compare::MAJOR); // true
```

##### Limit comparison to the major and minor versions only

[](#limit-comparison-to-the-major-and-minor-versions-only)

Ignores the patch and pre-release versions completely

```
$version1 = new SemVer\Version('v1.2.3-alpha.4');
$version2 = new SemVer\Version('v1.2.4-alpha.5');

$version1->gt($version2, Compare::MINOR);  // false
$version1->lt($version2, Compare::MINOR);  // false
$version1->eq($version2, Compare::MINOR);  // true
$version1->neq($version2, Compare::MINOR); // false
$version1->gte($version2, Compare::MINOR); // true
$version1->lte($version2, Compare::MINOR); // true
```

##### Limit comparison to the major, minor and patch versions only

[](#limit-comparison-to-the-major-minor-and-patch-versions-only)

Ignores the pre-release version completely

```
$version1 = new SemVer\Version('v1.2.3-alpha.4');
$version2 = new SemVer\Version('v1.2.3-alpha.5');

$version1->gt($version2, Compare::PATCH);  // false
$version1->lt($version2, Compare::PATCH);  // false
$version1->eq($version2, Compare::PATCH);  // true
$version1->neq($version2, Compare::PATCH); // false
$version1->gte($version2, Compare::PATCH); // true
$version1->lte($version2, Compare::PATCH); // true
```

Troubleshooting
---------------

[](#troubleshooting)

For general help and support join our [GitHub Discussions](https://github.com/PHLAK/SemVer/discussions) or reach out on [Bluesky](https://bsky.app/profile/phlak.dev).

Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/SemVer/issues).

Copyright
---------

[](#copyright)

This project is liscensed under the [MIT License](https://github.com/PHLAK/SemVer/blob/master/LICENSE).

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance62

Regular maintenance activity

Popularity57

Moderate usage in the ecosystem

Community37

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 85.8% 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 ~182 days

Recently: every ~225 days

Total

19

Last Release

338d ago

Major Versions

1.0.0 → 2.0.12017-09-07

2.0.1 → 3.0.02019-12-03

3.2.0 → 4.0.02021-08-25

4.1.0 → 5.0.02024-08-02

5.0.0 → 6.0.02024-09-19

PHP version history (8 changes)0.1.2PHP &gt;=5.4

2.0.1PHP &gt;=5.6

3.0.0PHP &gt;=7.0

3.1.0PHP &gt;=7.1

4.0.0PHP &gt;=7.2

5.0.0PHP ^8.0 || ^8.1 || ^8.2 || 8.3

6.0.0PHP ^8.1 || ^8.2 || ^8.3

6.1.0PHP ^8.1 || ^8.2 || ^8.3 || ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53531?v=4)[Chris Kankiewicz](/maintainers/PHLAK)[@PHLAK](https://github.com/PHLAK)

---

Top Contributors

[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (151 commits)")[![alessandroc-jt](https://avatars.githubusercontent.com/u/160012137?v=4)](https://github.com/alessandroc-jt "alessandroc-jt (4 commits)")[![jpickwell](https://avatars.githubusercontent.com/u/4682321?v=4)](https://github.com/jpickwell "jpickwell (4 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (4 commits)")[![oscar-ol](https://avatars.githubusercontent.com/u/16516316?v=4)](https://github.com/oscar-ol "oscar-ol (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![joint-tech](https://avatars.githubusercontent.com/u/171946096?v=4)](https://github.com/joint-tech "joint-tech (1 commits)")[![rikonek](https://avatars.githubusercontent.com/u/26687446?v=4)](https://github.com/rikonek "rikonek (1 commits)")[![MuhmdRaouf](https://avatars.githubusercontent.com/u/10425180?v=4)](https://github.com/MuhmdRaouf "MuhmdRaouf (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")[![beleneglorion](https://avatars.githubusercontent.com/u/210640?v=4)](https://github.com/beleneglorion "beleneglorion (1 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")[![cloud-arrow](https://avatars.githubusercontent.com/u/52516729?v=4)](https://github.com/cloud-arrow "cloud-arrow (1 commits)")

---

Tags

phpsemantic-versioningsemverversioning

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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