Luminova Framework

PHP Luminova: Compare Version Numbers and Constraints

Last updated: 2026-11-28 20:57:12

Compare numeric versions and check whether a version satisfies one or more constraints.

Use Version for numeric versions with up to three segments. Missing segments are compared as zero, and the current version accepts a lowercase v prefix. Separate combined constraints with spaces and keep each operator next to its version. Both ^ and ~ use the same boundaries in this utility. For example, ^3.8 allows versions from 3.8.0 up to but excluding 3.9.0, while ^3 extends to the next major version.


Usage

use Luminova\Utility\Version;

var_dump(Version::satisfies('v3.8.2', '>=3.8 <4')); // bool(true)
var_dump(Version::match('3.9.0', '^3.8')); // bool(false)
var_dump(Version::compare('3.8', '=', '3.8.0')); // bool(true)

Class Definition

  • Full namespace: Luminova\Utility\Version
  • This class is final.

Methods

satisfies

Evaluate whitespace-separated constraints as an AND expression. All constraints must pass. The method stops at the first failed comparison.

public static function satisfies(string $current, string $constraint): bool

Parameters:

ParameterTypeDescription
$currentstringCurrent numeric version.
$constraintstringOne or more constraints, such as >=3.8 <4.

Return:

bool - true if every comparison passes.

Throws:


compare

Compare two versions with one of >=, <=, >, <, !=, <>, =, or ==. Unsupported operators yield false.

public static function compare(string $current, string $operator, string $target): bool

Parameters:

ParameterTypeDescription
$currentstringCurrent numeric version.
$operatorstringComparison operator.
$targetstringTarget numeric version without a v prefix.

Return:

bool - true if the comparison passes.

Throws:


match

Evaluate one constraint. Interior whitespace is rejected, so write >=3.8 as one token.

public static function match(string $current, string $constraint): bool

Parameters:

ParameterTypeDescription
$currentstringCurrent numeric version.
$constraintstringA single comparison, range, or exact version.

Return:

bool - true if the version matches.

Throws: