Asymmetric Visibility: The "Read-Only" Solution We Needed
Theodoros Kafantaris
Published on December 06, 2025
One of the most common requirements in Object-Oriented Programming is: "I want everyone to be able to read this status, but only the class itself should be able to change it."
Previously, we had to make the property private and create a public getter. Now, PHP supports Asymmetric Visibility.
The Old Way:
class Order {
private string $status = 'pending';
public function getStatus(): string {
return $this->status;
}
}
The Modern Way:
class Order {
// Public to read, Private to set.
public private(set) string $status = 'pending';
public function complete(): void {
$this->status = 'completed'; // This works (internal)
}
}
$order = new Order();
echo $order->status; // Works!
$order->status = 'shipped'; // Error! Cannot set property.
Why use it? It is perfect for DTOs (Data Transfer Objects) and Entities. You get the safety of encapsulation with the simplicity of public properties.