What are some common pitfalls when writing PHP code for different server environments?

One common pitfall when writing PHP code for different server environments is not accounting for differences in PHP versions. To solve this issue, always check the PHP version before executing code that may not be compatible with older versions.

if (version_compare(PHP_VERSION, '7.0.0', '<')) {
    // Code that is only compatible with PHP 7 or higher
    echo "This code requires PHP version 7 or higher.";
} else {
    // Code that is compatible with PHP 5.x and PHP 7.x
    echo "This code is compatible with PHP version 5.x and PHP 7.x";
}