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

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

someshwer/version-comparison
============================

This Laravel package compares two version strings and gives the Boolean result. This package also resolves version expressions like (($v &gt; 1.24.0) &amp;&amp; ($v &lt; 1.25.1.0)) || ($v == 1.26 || $v == 1.27) where $v must be substituted with the version number to be compared. Hence the package can be used for version expressions evaluation.

2.1.1(7y ago)115MITPHPPHP ^5.4 || ^7.0CI failing

Since Oct 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/bsomeshwer/version-comparison)[ Packagist](https://packagist.org/packages/someshwer/version-comparison)[ Docs](https://github.com/bsomeshwer/version-comparison)[ RSS](/packages/someshwer-version-comparison/feed)WikiDiscussions master Synced 3d ago

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

version-comparison
==================

[](#version-comparison)

[![Total Downloads](https://camo.githubusercontent.com/448c0b7981f94b9040dada5c3d631a098a35afedd08449aa443841d5ce2ed8f9/68747470733a2f2f706f7365722e707567782e6f72672f736f6d6573687765722f76657273696f6e2d636f6d70617269736f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/someshwer/version-comparison)[![Latest Stable Version](https://camo.githubusercontent.com/b72a44e286475611928b9a3fe6f7e1f8048058d64ef3177efa57dc638fda7202/68747470733a2f2f706f7365722e707567782e6f72672f736f6d6573687765722f76657273696f6e2d636f6d70617269736f6e2f762f737461626c652e737667)](https://packagist.org/packages/someshwer/version-comparison)[![Latest Unstable Version](https://camo.githubusercontent.com/d396b7657ac077d7f1239ea0b50a12f58978b2c4ffc6b770e62d1db76b791fa2/68747470733a2f2f706f7365722e707567782e6f72672f736f6d6573687765722f76657273696f6e2d636f6d70617269736f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/someshwer/version-comparison)

This Laravel package compares two version strings and gives the Boolean result. This package also resolves version expressions like (($v &gt; 1.24.0) &amp;&amp; ($v &lt; 1.25.1.0)) || ($v == 1.26 || $v == 1.27) where $v must be substituted with the version number to be compared. Hence the package can be used for version expressions evaluation.

Installation
============

[](#installation)

To download the latest version, type the following line in terminal and then press enter. (Current stable version of this package is 2.1 LTS)

```
composer require someshwer/version-comparison

```

And then add the following service provider to **providers** array in config/app.php configuration file.

```
Ex: 'providers' => [
        ... ,
        ... ,
        Someshwer\VersionComparison\VersionComparisonServiceProvider::class
    ];

```

And add the following alias to **aliases** array in config/app.php configuration file.

```
Ex: 'aliases' => [
        ... ,
        .... ,
        'VersionComparator' => Someshwer\VersionComparison\Facades\VersionComparator::class
    ];

```

Now just simply publish the service provider by running following command in terminal. (Optional Step)

```
    $ php artisan vendor:publish --provider="Someshwer\VersionComparison\VersionComparisonServiceProvider"

    That's all! You are done with package installation...

```

Usage
=====

[](#usage)

1. VersionComparator::compare(): This method compares two version strings using specified operator and gives the Boolean result. It takes three parameters:

```
VersionComparator::compare(Version1 String, Operator String, Version2 String); // compare(Version1, Operator, Version2);

a. Version number (First Parameter)
b. Operator (Second Parameter)
c. Version number (Third Parameter)

Ex: VersionComparator::compare('1.2.5', '>', '1.2.2'); // Gives the Boolean result either TRUE or FALSE.
For this above example comparison, the result is TRUE.

```

2. VersionComparator::evaluate(): This method usually evaluates version expression in the following form: (("1.2" &gt; "1.24.0") &amp;&amp; ("1.2" &lt; "1.25.1.0")) || ("1.2" == "1.26" || "1.2" == "1.27") It takes only one argument that is expression of the above type.

```
VersionComparator::evaluate('Version Expression');

Ex: VersionComparator::evaluate('(("1.2" > "1.24.0") && ("1.2" < "1.25.1.0")) || ("1.2" == "1.26" || "1.2" == "1.27")');
// Gives Boolean result either TRUE or FALSE

```

3. VersionComparator::substituteThenEvaluate(): This method usually evaluates version expressions of the following type: (($v &gt; "1.24.0") &amp;&amp; ($v &lt; "1.25.1.0")) || ($v == "1.26" || $v == "1.27") This method takes two parameters. They are: a. First one is the version number to be substituted in place of $v in the expression. And b. The second one is the expression to be evaluated after $v is substituted.

Note: $v is the variable to be substituted with version number (First Parameter).

```
VersionComparator::substituteThenEvaluate('Version Number', 'Version Expression');

Ex: VersionComparator::substituteThenEvaluate('2.1.4', '((1.2 > 1.24.0) && (1.2 < 1.25.1.0)) || (1.2 == 1.26 || 1.2 == 1.27)');
Hence, in this example: $v in the expression is replaced by '2.1.4'.

After successful evaluation it gives the Boolean result either TRUE or FLASE.

```

---

```
Note: This package requires and depends on two other external third-party packages. They are:
1. composer/semver version 1.4.2 (https://github.com/composer/semver) and
2. symfony/expression-language version 4.1 (https://symfony.com/doc/current/components/expression_language.html).

You no need to manually install them in your project. They will be automatically downloaded to your vendor folder when ever
you install "someshwer/version-comparison" package by executing the following command in terminal.

-> composer require someshwer/version-comparison

```

Response
========

[](#response)

The response content must be json. The methods of this package almost always return the response in JSON format.

```
Example:

1. Sample success response:
{
   status: "SUCCESS",
   message: "Expression successfully evaluated!",
   error_message: false,
}

2. Sample validation error response:
{
   status: "ERROR",
   error_type: "validation",
   message: "Unable to evaluate the expression!",
   error_message: "Invalid expression! Unexpected ")" around position 44 for expression `(('1.2' > '1.24.0')) && ('1.2' < '1.25.1.0')) || ('1.2' == '1.26' || '1.2' == '1.27')`. Check log for more info.",
}

```

Note: If you want, you can also customize the response to the format which ever you want.!

Code snippet for testing:
=========================

[](#code-snippet-for-testing)

```
Route::get('/test', function () {

     $result_one = \VersionComparator::compare('1.2.8', '>', '1.2');

     $result_two = \VersionComparator::evaluate('((1.2.8 > 1.24.0) && (1.2.8 < 1.25.1.0)) || (1.2.8 == 1.26 || 1.2.8 == 1.27)');

     $result_three = \VersionComparator::substituteThenEvaluate('1.2', '(($v > 1.24.0) && ($v < 1.25.1.0)) || ($v == 1.26 || $v == 1.27)');

     // return compact('result_one', 'result_two', 'result_three');

     // return $result_one;
     // return $result_two;
     return $result_three;

});

```

If you want to test this package, copy and paste the above code in your web.php file and test this version-comparison/version-expression evaluation package.

Screenshot of code snippet:
===========================

[](#screenshot-of-code-snippet)

[![alt Code Snippet Screen Shot](https://raw.githubusercontent.com/bsomeshwer/version-comparison/master/src/Repo/Code-Snippet(i).PNG)](https://raw.githubusercontent.com/bsomeshwer/version-comparison/master/src/Repo/Code-Snippet(i).PNG)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

4

Last Release

2766d ago

Major Versions

1.3 → 2.1.12018-10-18

### Community

Maintainers

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

---

Top Contributors

[![bsomeshwer](https://avatars.githubusercontent.com/u/39646194?v=4)](https://github.com/bsomeshwer "bsomeshwer (28 commits)")

---

Tags

laravelphpversionscomparatorexpressionexpressionscomparisonEvaluationexpression evaluationversion-comparisonversion-comparatorevaluations

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[jean85/pretty-package-versions

A library to get pretty versions strings of installed dependencies

1.3k289.5M63](/packages/jean85-pretty-package-versions)[sllh/composer-versions-check

Checks if packages are up to date to last major versions after update

2352.4M16](/packages/sllh-composer-versions-check)[lorisleiva/cron-translator

Makes CRON expressions human-readable

3148.5M31](/packages/lorisleiva-cron-translator)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)[dragon-code/benchmark

Simple comparison of code execution speed between different options

11934.7k5](/packages/dragon-code-benchmark)

PHPackages © 2026

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