PHP versioning semantic-versioning
Need help with SemVer?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.


Semantic versioning helper library for PHP

137 Stars 11 Forks MIT License 106 Commits 1 Opened issues

Services available

Need anything else?



Semantic versioning helper library • Created by Chris Kankiewicz (@PHLAK)

Latest Stable Version Total Downloads License Build Status StyleCI
Join our Community Become a Sponsor One-time Donation



composer require phlak/semver


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

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

Or parse an incomple version string with the static

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


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

$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

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

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

Compare two SemVer objects

$version1 = new SemVer('v1.2.3');
$version2 = new SemVer('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


For general help and support join our Spectrum Community or reach out on Twitter.

Please report bugs to the GitHub Issue Tracker.


This project is liscensed under the MIT License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.