What are the best practices for checking PHP version compatibility in code?

When writing PHP code, it's important to ensure that the code is compatible with the PHP version it will be running on. One way to check PHP version compatibility in code is to use the PHP_VERSION constant and compare it against the minimum required version. By checking the PHP version before running specific code, you can prevent compatibility issues and errors.

$min_php_version = '7.2.0';

if (version_compare(PHP_VERSION, $min_php_version) < 0) {
    die('Minimum PHP version required is ' . $min_php_version);
}

// Code that requires PHP 7.2.0 or higher