What are the potential pitfalls of using global variables in PHP code?

Using global variables in PHP code can lead to several issues such as making code difficult to maintain, increasing the risk of naming conflicts, and hindering code reusability. To avoid these pitfalls, it is recommended to limit the use of global variables and instead use parameter passing or encapsulate variables within classes.

class Example {
    private $variable;

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

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

$example = new Example();
$example->setVariable('Hello World');
echo $example->getVariable();