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

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

steevanb/version-comparator
===========================

Compare PHP version easier than with version\_compare()

0.2.0(4y ago)0180[1 issues](https://github.com/steevanb/php-version-comparator/issues)1MITPHPPHP ^5.6 || ^7.0 || ^8.0

Since Oct 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/steevanb/php-version-comparator)[ Packagist](https://packagist.org/packages/steevanb/version-comparator)[ RSS](/packages/steevanb-version-comparator/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (1)

[![Version](https://camo.githubusercontent.com/85ea062aa86a42732b611f53b70686b1c9b32cf6ecc46e9d2cce197e1611b35b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d302e322e302d3442393038312e737667)](https://github.com/steevanb/php-version-comparator/tree/0.2.0)[![License](https://camo.githubusercontent.com/d08d09045472ccecb45acb1d13709abb95f9c06f0328a86b26ab0c1b264235c8/68747470733a2f2f706f7365722e707567782e6f72672f7374656576616e622f76657273696f6e2d636f6d70617261746f722f6c6963656e7365)](https://github.com/steevanb/php-version-comparator/blob/master/LICENSE)[![PHP](https://camo.githubusercontent.com/c7d81e52983bf67fe8f32eabfb0c39f19d75a0fcc8f5e6d91078cb15e60560b6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545352e33253743253743253545372e30253743253743253545382e302d626c75652e737667)](https://php.net)[![Lines](https://camo.githubusercontent.com/edd7eaa9671348348e6cfa9af59d4c6b41920176d561ea6661da41e091fd071f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532306c696e65732d342c3536312d626c75652e737667)](https://camo.githubusercontent.com/edd7eaa9671348348e6cfa9af59d4c6b41920176d561ea6661da41e091fd071f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532306c696e65732d342c3536312d626c75652e737667)[![Downloads](https://camo.githubusercontent.com/75ca6c15de7c345ee04306535dd60b8aa20b0184ba79e606b90b0ea96a371da8/68747470733a2f2f706f7365722e707567782e6f72672f7374656576616e622f76657273696f6e2d636f6d70617261746f722f646f776e6c6f616473)](https://camo.githubusercontent.com/75ca6c15de7c345ee04306535dd60b8aa20b0184ba79e606b90b0ea96a371da8/68747470733a2f2f706f7365722e707567782e6f72672f7374656576616e622f76657273696f6e2d636f6d70617261746f722f646f776e6c6f616473)

[![CI](https://github.com/steevanb/php-version-comparator/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/steevanb/php-version-comparator/actions/workflows/ci.yml)[![Tests](https://camo.githubusercontent.com/2c899e95a2fb8bf0f2477c3bf66fde2ebdeef8fa663ad68a9526ebc46771d5e0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d34302d626c75652e737667)](https://camo.githubusercontent.com/2c899e95a2fb8bf0f2477c3bf66fde2ebdeef8fa663ad68a9526ebc46771d5e0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d34302d626c75652e737667)[![Assertions](https://camo.githubusercontent.com/35981e60cf70ca6b7d08b2b53137e90cbd89e027fca07c966d6579a8bf70b99a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617373657274696f6e732d37302d626c75652e737667)](https://camo.githubusercontent.com/35981e60cf70ca6b7d08b2b53137e90cbd89e027fca07c966d6579a8bf70b99a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617373657274696f6e732d37302d626c75652e737667)[![Coverage](https://camo.githubusercontent.com/6d3f8335589617f63dd442836b1460c3cb4ae696090b4246bf2ea9dbc53a2677/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d37302532352d737563636573732e737667)](https://camo.githubusercontent.com/6d3f8335589617f63dd442836b1460c3cb4ae696090b4246bf2ea9dbc53a2677/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d37302532352d737563636573732e737667)[![Infection](https://camo.githubusercontent.com/b80b85f8031c49aa6ee45c6cd470d348f84c0c2e8ace0bc7a545dfc1f73ee29a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e66656374696f6e2d39352532352d737563636573732e737667)](https://camo.githubusercontent.com/b80b85f8031c49aa6ee45c6cd470d348f84c0c2e8ace0bc7a545dfc1f73ee29a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f696e66656374696f6e2d39352532352d737563636573732e737667)

steevanb/version-comparator
---------------------------

[](#steevanbversion-comparator)

Add classes to compare versions easier than with `compare_version()` and `PHP_VERSION`.

[Changelog](changelog.md)

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

[](#installation)

```
composer require steevanb/version-comparator ^0.2

```

Compare with current PHP version
--------------------------------

[](#compare-with-current-php-version)

You can compare current PHP version with 2 versions to know if current php version is between this 2 versions:

```
PhpVersionComparator::isBetween('8', '9'); // return true is PHP is >= 8.0.0 and < 9.0.0
PhpVersionComparator::isBetween('8.0', '8.1'); // return true is PHP is >= 8.0.0 and < 8.1.0
PhpVersionComparator::isBetween('8.0.0', '8.0.2'); // return true is PHP is >= 8.0.0 and < 8.0.2
```

Shortcuts for each PHP major and minor version
----------------------------------------------

[](#shortcuts-for-each-php-major-and-minor-version)

`PhpVersionComparator` have a shortcut who call `isBetween()` for each major and minor version:

```
// For PHP 5.3 to 5.6
PhpVersionComparator::isPhp5(); // return true is PHP is >= 5.0.0 and < 6.0.0
PhpVersionComparator::isPhp53(); // return true is PHP is >= 5.3.0 and < 5.4.0
PhpVersionComparator::isPhp54(); // return true is PHP is >= 5.4.0 and < 5.5.0
PhpVersionComparator::isPhp55(); // return true is PHP is >= 5.5.0 and < 5.6.0
PhpVersionComparator::isPhp56(); // return true is PHP is >= 5.6.0 and < 5.7.0

// For PHP 7.0 to 7.4
PhpVersionComparator::isPhp7(); // return true is PHP is >= 7.0.0 and < 8.0.0
PhpVersionComparator::isPhp70(); // return true is PHP is >= 7.0.0 and < 7.1.0
PhpVersionComparator::isPhp71(); // return true is PHP is >= 7.1.0 and < 7.2.0
PhpVersionComparator::isPhp72(); // return true is PHP is >= 7.2.0 and < 7.3.0
PhpVersionComparator::isPhp73(); // return true is PHP is >= 7.3.0 and < 7.4.0
PhpVersionComparator::isPhp74(); // return true is PHP is >= 7.4.0 and < 7.5.0

// For PHP 8.0 to latest 8.x
PhpVersionComparator::isPhp8(); // return true is PHP is >= 8.0.0 and < 9.0.0
PhpVersionComparator::isPhp80(); // return true is PHP is >= 8.0.0 and < 8.1.0
PhpVersionComparator::isPhp81(); // return true is PHP is >= 8.1.0 and < 8.2.0
```

Exception instead of returning the result
-----------------------------------------

[](#exception-instead-of-returning-the-result)

If you want to throw an exception instead of returning the result, each method have it's `assert()` version who throw a `VersionIsNotBetweenException` exception:

```
PhpVersionComparator::assertIsBetween('8', '9');
PhpVersionComparator::assertIsPhp5();
// etc
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

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

Total

3

Last Release

1668d ago

### Community

Maintainers

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

---

Top Contributors

[![steevanb](https://avatars.githubusercontent.com/u/5063383?v=4)](https://github.com/steevanb "steevanb (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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