This package is abandoned and no longer maintained. The author suggests using the composer/semver package instead.

SemVer 2.0.0 compliant semantic versioning tools, ranges, filters, sorters and collections

0.2.1 2016-04-05 08:41 UTC

This package is auto-updated.

Last update: 2021-02-05 19:41:47 UTC


Build Status Scrutinizer Coverage Scrutinizer SensioLabs Insight GitHub license

Semantic Versioning implementation for PHP including constraints, filters, sorting and iterable map. Conforms to Semver specification 2.0.0 but also support loose parsing of non-compliant but similar versioning systems.

All core features like the parsing and processing of versions and expressions are implemented and 100% unit tested, but the library is not yet feature complete. Active development is currently on hold. Visit the open issues to see what's on the list before going 1.0.0.


Packagist Packagist

The recommended way to install this library is through Composer:

composer require omines/semver

If you're not familiar with composer follow the installation instructions for Linux/Unix/Mac or Windows, and then read the basic usage introduction.


Code says more than a thousand words:

// Versions
$first = new Version('0.1.2-alpha.1-build.684');
$second = Version::fromString('1.2.3');
$third = new Version('2.4.6');

// Comparison
$first->greaterThan($second);               // false
$first->greaterThanOrEqual($second);        // false
$first->lessThan($second);                  // true
$first->lessThanOrEqual($second);           // true
$first->equals($second);                    // false
$first->compare($second);                   // negative
$second->compare($first);                   // positive
$first->compare($first);                    // 0

// Utility (can use either varargs or an array)
Version::highest($first, $second, $third);  // $third
Version::lowest([$first, $second, $third]); // $first

// Expressions
$expression = Expression::fromString('>=2.3 || ^1.2');
$expression->matches($first);               // false
$second->matches($expression);              // true

// List
$list = new VersionList([$third, $second]);
$list[] = $second;
$list[1] = $first;
$list[1] == $second;                        // true
foreach ($list as $version) { ... }         // $version instanceof Version
$list->each($closure);                      // calls closure with every element

// Map
$map = new VersionMap([
    $first => 'Package 1'
$map[$second] = 'Package 2';
foreach ($map as $key => $value) { ... }    // $key instanceof Version
$map->each($closure);                       // calls closure with every (&$value, $key)

If errors occur a SemverException is thrown.


If you run into problems using this library, or would like to request additional features, please open an issue.

Pull requests are only considered if they follow PSR-2 coding standards and include full unit tests maintaining coverage on files and lines.


This software was developed for internal use at Omines Full Service Internetbureau in Eindhoven, the Netherlands. It is shared with the general public under the permissive MIT license, without any guarantee of fitness for any particular purpose. Refer to the included LICENSE file for more details.