What are the potential pitfalls of using global variables within a class in PHP?

Using global variables within a class in PHP can lead to tight coupling and make the code harder to maintain and test. To solve this issue, it's better to use class properties instead of global variables to encapsulate data within the class and reduce dependencies on external variables.

class MyClass {
    private $myVariable;

    public function setVariable($value) {
        $this->myVariable = $value;
    }

    public function getVariable() {
        return $this->myVariable;
    }
}

$myObject = new MyClass();
$myObject->setVariable("Hello, World!");
echo $myObject->getVariable(); // Output: Hello, World!