What are the best practices for ensuring PHP scripts are compatible with different PHP versions, such as PHP 5.4?

To ensure PHP scripts are compatible with different PHP versions, such as PHP 5.4, it is important to avoid using deprecated functions, features, and syntax that are no longer supported in newer PHP versions. Additionally, it is recommended to use version-specific conditional checks and to test the code on different PHP versions to ensure compatibility.

// Example of version-specific conditional check for PHP 5.4 compatibility
if (version_compare(PHP_VERSION, '5.4', '<')) {
    // Code that is only compatible with PHP versions below 5.4
} else {
    // Code that is compatible with PHP 5.4 and above
}