What are the best practices for handling private properties in PHP classes?

When working with private properties in PHP classes, it is best practice to use getter and setter methods to access and modify these properties. This helps to encapsulate the data and control how it is accessed and modified, ensuring data integrity and security.

class MyClass {
    private $privateProperty;

    public function getPrivateProperty() {
        return $this->privateProperty;
    }

    public function setPrivateProperty($value) {
        $this->privateProperty = $value;
    }
}

// Usage example
$obj = new MyClass();
$obj->setPrivateProperty("Hello");
echo $obj->getPrivateProperty(); // Output: Hello