What are some potential pitfalls when transitioning from procedural to object-oriented programming in PHP?

One potential pitfall when transitioning from procedural to object-oriented programming in PHP is the improper handling of global variables. In procedural programming, global variables are commonly used, but in object-oriented programming, it's best to avoid them as they can lead to dependencies and make code harder to maintain. To solve this issue, encapsulate data within classes and use methods to access and modify the data.

class User {
    private $username;

    public function setUsername($username) {
        $this->username = $username;
    }

    public function getUsername() {
        return $this->username;
    }
}

$user = new User();
$user->setUsername('JohnDoe');
echo $user->getUsername(); // Output: JohnDoe