What are some best practices for creating a PHP class to represent data types like measurement values?

When creating a PHP class to represent measurement values, it's important to ensure that the class is well-structured, easily extensible, and follows best practices for object-oriented programming. This includes defining properties and methods that accurately represent the data type, using appropriate access modifiers, and implementing validation and conversion methods as needed.

<?php

class MeasurementValue {
    private $value;
    private $unit;

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

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

    public function getUnit() {
        return $this->unit;
    }

    public function convertTo($newUnit) {
        // Add conversion logic here
    }

    public function validate() {
        // Add validation logic here
    }
}

// Example usage
$measurement = new MeasurementValue(10, 'cm');
echo $measurement->getValue(); // Output: 10
echo $measurement->getUnit(); // Output: cm
$measurement->convertTo('m');
$measurement->validate();