Helper class to get a current version from composer.json
file in your project
If you want to get only string version, you can use mazanax/composer-project-version
composer require mazanax/composer-version-semver
<?php
$packageVersion = \MZNX\ComposerPackageSemver\PackageVersionSemver::init(__DIR__ . '/path/to/composer.json');
$version = $packageVersion->getVersion();
echo $version->getMajor() . PHP_EOL;
echo $version->getMinor() . PHP_EOL;
echo $version->getPatch() . PHP_EOL;
<?php
$packageVersion = \MZNX\ComposerPackageSemver\PackageVersionSemver::init(__DIR__ . '/path/to/composer.json');
$version = $packageVersion->getVersionAsString();
echo $version . PHP_EOL;
MIT