- var_dump: documentation ( source)
- preg_match: documentation ( source)
<?php
class Foo
{
const VERSION_INFO = '12abc34 (HEAD -> master, tag: 2.0.1)';
static function getVersion(): string
{
if (self::VERSION_INFO[0] === '$') {
// fallback to other methods
return '';
}
if (preg_match('/^([0-9a-f]+).*?tag: ([\d\.]+)/', self::VERSION_INFO, $matched)) {
return "{$matched[2]}-{$matched[1]}";
}
// fallback to other methods
}
}
var_dump(Foo::getVersion());