PHPackages                             ptlis/semantic-version - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ptlis/semantic-version

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ptlis/semantic-version
======================

Tools for working with semantic version numbers.

v0.11.0(9y ago)4376MITPHPPHP &gt;=5.5.0

Since Jan 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ptlis/semantic-version)[ Packagist](https://packagist.org/packages/ptlis/semantic-version)[ RSS](/packages/ptlis-semantic-version/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (13)Used By (0)

SemanticVersion
===============

[](#semanticversion)

A modular, extensible library for PHP &gt;= 5.6 providing APIs to support parsing &amp; manipulation of semantic version numbers, comparators, ranges &amp; collections.

The [Semantic Versioning Specification](http://semver.org/) describes the semantics and precedence rules used when parsing &amp; manipulating version numbers etc.

[![Build Status](https://camo.githubusercontent.com/036c373b529050757380535cf6911500f70ee5e17a94da75fc1ad00c497f04c6/68747470733a2f2f7472617669732d63692e6f72672f70746c69732f73656d616e7469632d76657273696f6e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/ptlis/semantic-version) [![Code Coverage](https://camo.githubusercontent.com/5eda59ed614517df3b66848cbb2aaae353d80e456a6ca08d92152c838709680d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70746c69732f73656d616e7469632d76657273696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ptlis/semantic-version/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/da1036b49d68270b5b990c44eff2e1fb05479f07a4e735fd9fec2077b6d78d00/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70746c69732f73656d616e7469632d76657273696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ptlis/semantic-version/?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/06dc3947c22dfa8071c41e6331b084207e6939aa939d9124576885da89861da9/68747470733a2f2f706f7365722e707567782e6f72672f70746c69732f73656d616e7469632d76657273696f6e2f762f737461626c652e706e67)](https://packagist.org/packages/ptlis/semantic-version)

Usage
-----

[](#usage)

### Parse Version

[](#parse-version)

First create an instance of the VersionEngine:

```
    use ptlis\SemanticVersion\VersionEngine();

    $engine = new VersionEngine();
```

Then call the `parseVersion` method passing a version number:

```
    $version = $engine->parseVersion('1.5.0-rc.1');
```

On failure to parse a `\RuntimeException` will be thrown.

### Parse Version Range

[](#parse-version-range)

Again, create an instance of the VersionEngine:

```
    use ptlis\SemanticVersion\VersionEngine();

    $engine = new VersionEngine();
```

Then call the `parseVersionRange` method passing a version range:

```
    $version = $engine->parseVersion('1.5.0-3.0.0');
```

As before, on failure to parse a `\RuntimeException` will be thrown.

### Versions

[](#versions)

The Version class provides a simple value type representing a semantic version number.

It provides simple accessors for the components of a semantic version number:

```
    echo $version->getMajor();  // '1'
    echo $version->getMinor();  // '5'
    echo $version->getPatch();  // '0'
    echo $version->getLabel();  // 'rc.1'
```

A `__toString` implementation:

```
    echo $version;  // '1.5.0-rc.1'
```

Version also implement `SatisfiedByVersionInterface` so offer the `isSatisfiedBy` method which returns true if the versions match.

### Version Ranges

[](#version-ranges)

Version ranges are bundles of objects representing a version range constraint, represented by classes implementing `VersionRangeInterface`.

The simplest version range is a version and a comparator (e.g. `>=2.5.3`, '&lt;1.0.0'), which is expressed by the `ComparatorVersion` class.

A more complex range would be one with an upper and lower bound (e.g. `~1.0.0`, '^1.0.0', '&gt;=1.0.0,&lt;2.0.0' which are all equivalent). This is expressed via the `LogicalAnd` class wrapping two `ComparatorVersion` instances.

The most complex constraint would be one containing two ranges (e.g. `1.2.5-2.3.2|^4.0.0`). This is expressed via Wrapping the two classes implementing `VersionRangeInterface`.

As `VersionRangeInterface` extends `SatisfiedByVersionInterface` these implement the `isSatisfiedBy` method which returns true if the passed version satisfies the constraint.

Known limitations
-----------------

[](#known-limitations)

There currently are a few areas where this library deviates from the specification when dealing with labels &amp; build metadata; this is to due to how the parsing of version-ranges is handled. However, having tested the parsing code against the complete list of packages scraped from packagist I found no packages affected by this.

Example semantic versions which are valid but the library is unable to parse:

- 1.0.0-0.3.7
- 1.0.0-beta-17

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~110 days

Recently: every ~298 days

Total

12

Last Release

3306d ago

PHP version history (4 changes)v0.1.0PHP &gt;=5.4.0

v0.9.0PHP &gt;=5.3.0

v0.10.0PHP &gt;=5.6.0

v0.11.0PHP &gt;=5.5.0

### Community

Maintainers

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

---

Top Contributors

[![ptlis](https://avatars.githubusercontent.com/u/508422?v=4)](https://github.com/ptlis "ptlis (311 commits)")

---

Tags

parsingphpsemanticsemantic-versionssemverversionversioningsemanticversion

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ptlis-semantic-version/health.svg)

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

###  Alternatives

[nikolaposa/version

Value Object that represents a SemVer-compliant version number.

1406.4M16](/packages/nikolaposa-version)[shivas/versioning-bundle

Symfony application versioning, simple console command to manage version (with providers e.g. git tag) of your application using Semantic Versioning 2.0.0 recommendations

1121.2M1](/packages/shivas-versioning-bundle)[pragmarx/version

Take control over your Laravel app version

5921.2M2](/packages/pragmarx-version)[naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

72496.2k13](/packages/naneau-semver)[ergebnis/version

Provides an abstraction of a semantic version.

1813.6k](/packages/ergebnis-version)

PHPackages © 2026

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