What are the best practices for handling protected variables in PHP inheritance?

When dealing with protected variables in PHP inheritance, it is important to follow best practices to ensure proper encapsulation and maintainability of the code. One common approach is to use getter and setter methods to access and modify the protected variables in child classes. This allows for controlled access to the variables while still maintaining the benefits of inheritance.

class ParentClass {
    protected $protectedVariable;

    public function getProtectedVariable() {
        return $this->protectedVariable;
    }

    public function setProtectedVariable($value) {
        $this->protectedVariable = $value;
    }
}

class ChildClass extends ParentClass {
    public function modifyProtectedVariable($value) {
        $this->setProtectedVariable($value);
    }
}