What are the implications of using global variables in legacy PHP code and how can they be addressed?

Using global variables in legacy PHP code can lead to various issues such as code complexity, difficulty in debugging, and potential conflicts with other parts of the application. To address this, global variables should be minimized and encapsulated within classes or functions to reduce their impact on the overall codebase.

```php
class GlobalData {
    private static $data = [];

    public static function set($key, $value) {
        self::$data[$key] = $value;
    }

    public static function get($key) {
        return isset(self::$data[$key]) ? self::$data[$key] : null;
    }
}
```

This code snippet demonstrates a simple implementation of encapsulating global data within a class. Instead of using global variables directly, you can use the `GlobalData` class to set and get data values. This approach helps in organizing and managing global data more effectively.