How can the use of GLOBALS superglobals be avoided when globalizing objects in PHP?

Using GLOBALS superglobals to globalize objects in PHP is not recommended as it can lead to potential security vulnerabilities and make code harder to maintain. Instead, a more structured approach like using a Singleton pattern or dependency injection can be used to access objects globally without relying on superglobals.

class Database {
    private static $instance;

    public static function getInstance() {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    // Other database related methods
}

// Usage
$database = Database::getInstance();