What is the significance of declaring variables and methods as private or public in PHP OOP?

Declaring variables and methods as private or public in PHP OOP is significant for controlling access to these elements within a class. By marking variables or methods as private, they can only be accessed within the class itself, while marking them as public allows access from outside the class. This helps to enforce encapsulation and maintain the integrity of the class by preventing direct manipulation of its internal state from outside sources.

class Example {
    private $privateVar;
    public $publicVar;

    private function privateMethod() {
        // do something
    }

    public function publicMethod() {
        // do something
    }
}