What potential pitfalls can arise when using classes in PHP, as demonstrated in the provided code snippet?

One potential pitfall when using classes in PHP is not properly initializing class properties, which can lead to unexpected behavior or errors. To solve this issue, ensure that all class properties are initialized either in the class constructor or directly when declaring them.

class Person {
    private $name;
    private $age;

    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }

    public function getName() {
        return $this->name;
    }

    public function getAge() {
        return $this->age;
    }
}

$person = new Person("John", 30);
echo $person->getName(); // Output: John
echo $person->getAge(); // Output: 30