https://github.com/steevanb/php-version-comparator
Compare PHP version easier than with version_compare()
https://github.com/steevanb/php-version-comparator
Last synced: 3 months ago
JSON representation
Compare PHP version easier than with version_compare()
- Host: GitHub
- URL: https://github.com/steevanb/php-version-comparator
- Owner: steevanb
- License: mit
- Created: 2021-10-23T14:28:30.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-23T22:57:37.000Z (over 3 years ago)
- Last Synced: 2025-03-12T02:47:35.073Z (4 months ago)
- Language: PHP
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/steevanb/php-version-comparator/tree/0.2.0)
[](https://github.com/steevanb/php-version-comparator/blob/master/LICENSE)
[](https://php.net)

[](https://github.com/steevanb/php-version-comparator/actions/workflows/ci.yml)



## steevanb/version-comparator
Add classes to compare versions easier than with `compare_version()` and `PHP_VERSION`.
[Changelog](changelog.md)
## Installation
```
composer require steevanb/version-comparator ^0.2
```## 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:
```php
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
`PhpVersionComparator` have a shortcut who call `isBetween()` for each major and minor version:
```php
// 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
If you want to throw an exception instead of returning the result,
each method have it's `assert()` version who throw a `VersionIsNotBetweenException` exception:```php
PhpVersionComparator::assertIsBetween('8', '9');
PhpVersionComparator::assertIsPhp5();
// etc
```