What are the potential compatibility issues when running PHP scripts on different server environments with varying versions of PHP?

When running PHP scripts on different server environments with varying versions of PHP, compatibility issues may arise due to differences in language features, functions, or extensions. To ensure compatibility, it is essential to check the PHP version requirements of the script and the server environment. Additionally, using version-specific functions or features may lead to errors on servers running older PHP versions. To address this issue, consider using polyfills or alternative functions that are compatible across different PHP versions.

// Example of using a polyfill for a PHP function that is only available in newer versions

if (!function_exists('random_int')) {
    function random_int($min, $max) {
        return mt_rand($min, $max);
    }
}

// Usage of the random_int function
$randomNumber = random_int(1, 10);
echo $randomNumber;