DEV Community

Recca Tsai
Recca Tsai

Posted on • Originally published at recca0120.github.io

Get Package Versions at Runtime with Composer 2

Originally published at recca0120.github.io

Sometimes you need to check a Composer package's version at runtime, e.g., for backward compatibility or feature flags.

Using InstalledVersions

Composer 2's built-in InstalledVersions class can query the version of any installed package:

use Composer\InstalledVersions;

InstalledVersions::getVersion('laravel/framework');
Enter fullscreen mode Exit fullscreen mode

Top comments (0)