In what situations is it advisable to use private, protected, or public visibility for class properties in PHP, particularly when dealing with measurement values?

When dealing with measurement values in PHP classes, it is advisable to use private visibility for class properties to encapsulate the data and prevent direct access from outside the class. This helps maintain data integrity and ensures that the values are accessed and manipulated only through class methods, allowing for better control and validation of the measurement values.

class Measurement {
    private $value;

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

    public function getValue() {
        return $this->value;
    }

    public function setValue($value) {
        // Add validation logic here if needed
        $this->value = $value;
    }
}

$measurement = new Measurement(10);
echo $measurement->getValue(); // Output: 10
$measurement->setValue(20);
echo $measurement->getValue(); // Output: 20