What are the best practices for handling global variables in PHP without using the "global" keyword?

Global variables in PHP can lead to code that is hard to maintain and debug. Instead of using the "global" keyword, it's recommended to encapsulate global variables within a class and access them using static methods. This approach keeps the global state contained and provides a clear interface for accessing and modifying global variables.

class GlobalVariables {
    private static $globalVar = 'initial value';

    public static function getGlobalVar() {
        return self::$globalVar;
    }

    public static function setGlobalVar($value) {
        self::$globalVar = $value;
    }
}

// Accessing global variable
echo GlobalVariables::getGlobalVar();

// Modifying global variable
GlobalVariables::setGlobalVar('new value');
echo GlobalVariables::getGlobalVar();