What are some common pitfalls when migrating PHP scripts from PHP 5 to PHP 4.x?

One common pitfall when migrating PHP scripts from PHP 5 to PHP 4.x is the use of new features and functions that are not supported in PHP 4.x. To solve this issue, you will need to refactor your code to use older, compatible functions and syntax.

// PHP 5 code using unsupported function
$result = json_encode($data);

// PHP 4.x compatible code
$result = json_encode_compat($data);

function json_encode_compat($data) {
    if (function_exists('json_encode')) {
        return json_encode($data);
    } else {
        // Implement JSON encoding manually
        // Example implementation: 
        $json = '';
        foreach ($data as $key => $value) {
            $json .= '"' . $key . '":"' . $value . '",';
        }
        $json = '{' . rtrim($json, ',') . '}';
        return $json;
    }
}