What potential pitfalls should be avoided when using global variables in PHP classes?

Using global variables in PHP classes can lead to issues with encapsulation and can make the code harder to maintain and debug. To avoid these pitfalls, it's recommended to use class properties instead of global variables to store and access data within a class.

class MyClass {
    private $myProperty;

    public function __construct($value) {
        $this->myProperty = $value;
    }

    public function getMyProperty() {
        return $this->myProperty;
    }

    public function setMyProperty($value) {
        $this->myProperty = $value;
    }
}

// Example usage
$myObject = new MyClass('initial value');
echo $myObject->getMyProperty(); // Output: initial value
$myObject->setMyProperty('new value');
echo $myObject->getMyProperty(); // Output: new value