Skip to content

Functions

Mark King edited this page Sep 25, 2026 · 4 revisions

Functions

php-alpm provides three top-level (non-class) functions.

alpm_vercmp()

function alpm_vercmp(string $ver1, string $ver2): int

Compares two pacman version strings the same way pacman -Q / libalpm does (epoch, then pkgver, then pkgrel).

  • Returns -1 if $ver1 is older than $ver2
  • Returns 0 if they're equal
  • Returns 1 if $ver1 is newer than $ver2
echo alpm_vercmp("1.2.4-1", "1.5.3-2");   // -1
echo alpm_vercmp("1:1.5.2-1", "6.22.3-2"); // 1  (epoch wins)
echo alpm_vercmp("1.2-1", "1.2-1");        // 0

alpm_version()

function alpm_version(): string

Returns the version of the libalpm the extension was built against and is currently linked to, e.g. "16.0.1".

echo alpm_version();

php_alpm_version()

function php_alpm_version(): string

Returns the version of the php-alpm extension itself, e.g. "0.9".

echo php_alpm_version();

Clone this wiki locally