3v4l.org

run code in 300+ PHP versions simultaneously
<?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());

preferences:
57.98 ms | 405 KiB | 5 Q