PHPackages                             jelix/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. jelix/version

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

jelix/version
=============

Parse any version syntax, including semantic version. Compare version, using Composer version constraints syntax.

v2.0.2(4mo ago)13217.5k↓36%13MITPHPPHP &gt;=5.6CI failing

Since May 16Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/jelix/version)[ Packagist](https://packagist.org/packages/jelix/version)[ Docs](http://jelix.org)[ RSS](/packages/jelix-version/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (2)Versions (11)Used By (3)

This PHP library parse any version syntax, including [semantic version](https://semver.org). It allows also to compare versions, using Composer version constraints syntax.

installation
============

[](#installation)

You can install it from Composer. In your project:

```
composer require "jelix/version"

```

Usage
=====

[](#usage)

Parsing
-------

[](#parsing)

Use the `Jelix\Version\Parser` class to retrieve a `Jelix\Version\Version` object containing all versions informations.

```
$version = \Jelix\Version\Parser::parse('1.2.3b2');

$version->toString(); // '1.2.3-beta.2'
$version->getMajor(); // 1
$version->getMinor(); // 2
$version->getPatch(); // 3
$version->getStabilityVersion(); // array('beta', '2')

$version->getNextMajorVersion(); // Version object for '2.0.0'
$version->getNextMinorVersion(); // Version object for '1.3.0'
$version->getNextPatchVersion(); // Version object for '1.2.4'
$version->getBranchVersion(); // '1.2'
```

Example of supported version syntaxes:

- 1.0, 1.2.3
- 1.2-alpha, 1.2a, 1.2alpha, 1.2alpha.3, 1.2a1.3
- 1.2.3-beta, 1.2b, 1.2beta, 1.2beta.3, 1.2b3.4
- 1.2RC, 1.2-rc.4.5
- 1.2-dev, 1.2b1-dev, 1.2b1-dev.9, 1.2RC-dev, 1.2RC2-dev.1700

The parser support also 'secondary versions', i.e. versions appended to a version after a `-` or a `:`.

Ex: `1.2.3-1.4.5`, `1.2.3:1.4.5`. Here, `1.4.5` is a secondary version.

When retrieving a `Version` object for such versions, you can access to the secondary version through a method `getSecondaryVersion()` which returns a `Version` object:

```
$version = \Jelix\Version\Parser::parse('1.2.3:1.4.5');

$version->toString(); // '1.2.3:1.4.5'
$version->toString(true, false); // '1.2.3'

$version2 = $version->getSecondaryVersion();
$version2->toString(); // '1.4.5'

$version->getNextMajorVersion(); // Version object for '2.0.0'
$version->getNextMinorVersion(); // Version object for '1.3.0'
$version->getNextPatchVersion(); // Version object for '1.2.4'
$version->getBranchVersion(); // '1.2'
```

Simple comparison
-----------------

[](#simple-comparison)

```
$v1 = '1.2.3';
$v2 = '1.4.5';
$result = \Jelix\Version\VersionComparator::compareVersion($v1, $v2);
```

`compareVersion()` returns:

- `-1` if $v1 &lt; $v2
- `0` if $v1 == $v2
- `1` if $v1 &gt; $v2

Example to compare two versions:

```
\Jelix\Version\VersionComparator::compareVersion('1.2pre','1.2RC');
```

Secondary versions are also compared if primary versions are equals. In this case, if one of the version string does not contain a secondary version, then it is considered having the '0.0' version number, so it is considered as lower version than the version having a secondary version.

You have also an other method `compare()` taking `Version` objects as parameters:

```
$v1 = \Jelix\Version\Parser::parse('1.2.3');
$v2 = \Jelix\Version\Parser::parse('1.4.5');
$result = \Jelix\Version\VersionComparator::compare($v1, $v2);
```

Comparison with range
---------------------

[](#comparison-with-range)

`compareVersionRange()` allows you to use operator to compare version. It is compatible with version constraints supported by Composer.

- comparison operators: `>`, `=`, `=1.2 =1.2.3 =1.2.3 =0.3.0 =1.0.0 =1.0.0 getSecondaryVersion();
$version2->toString(); // '1.0.0'

\Jelix\Version\VersionComparator::compareVersionRange($version2, '>=1.2.*'); // returns false
```

History
=======

[](#history)

Ancesters of these classes have been included for years into the [Jelix Framework](http://jelix.org)until Jelix 1.6, and has been released in 2016 into a separate repository.

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance74

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity64

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

Recently: every ~528 days

Total

9

Last Release

148d ago

Major Versions

v1.1.0 → v2.0.02020-06-11

v1.1.2 → v2.0.22026-03-23

PHP version history (2 changes)v1.0.0PHP &gt;=5.3.3

v1.1.0-rc.1PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/ae8142be36568660282368ce7c1eec904ecbc515ab5b58c759a487f3a6f1d114?d=identicon)[laurentj](/maintainers/laurentj)

![](https://www.gravatar.com/avatar/baa42c7323bbc9245b0c70f770031383879941a1a813f678f2835699fd50b375?d=identicon)[mdouchin](/maintainers/mdouchin)

---

Top Contributors

[![laurentj](https://avatars.githubusercontent.com/u/336034?v=4)](https://github.com/laurentj "laurentj (38 commits)")

---

Tags

composercomparatorsemverversion

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nikolaposa/version

Value Object that represents a SemVer-compliant version number.

1417.7M24](/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

1101.3M1](/packages/shivas-versioning-bundle)[bizkit/versioning-bundle

Symfony bundle which provides a way to version your application using various versioning strategies.

1090.1k](/packages/bizkit-versioning-bundle)

PHPackages © 2026

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