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

To ensure PHP version compatibility before deploying code, it is essential to check the minimum required PHP version specified in the project's documentation or dependencies. This can be done by using PHP's predefined constant PHP_VERSION_ID to compare against the required version. Additionally, utilizing tools like Composer or PHP compatibility checkers can help identify any potential compatibility issues before deployment.

$required_php_version = 70100; // Minimum required PHP version (7.1.0)

if (PHP_VERSION_ID < $required_php_version) {
    die('Error: Minimum PHP version required is 7.1.0');
}