Asymmetric Visibility: The "Read-Only" Solution We Needed

Asymmetric Visibility: The "Read-Only" Solution We Needed

T

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:

Code
                    class Order {
    private string $status = 'pending';

    public function getStatus(): string {
        return $this->status;
    }
}
                

The Modern Way:

Code
                    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.

Share this post

Challenge Your Mind

NEW!

Take a break from reading and test your logic skills with our daily puzzle!

Latest Challenge: Dec 7, 2025

Daily Logic Ladder - Jean-Jacques Rousseau

Play Today's Puzzle

About Our Blog

Explore where technology meets intellect. From technical tutorials to intellectual exploration—stay curious and inspired.

â’¸ 2025. All rights reserved by atomic