Access Modifiers
Access modifiers control visibility. They define where properties and methods can be accessed from.
There are three levels of visibility in PHP.
public is the least restrictive. Properties and methods marked as public can be accessed from anywhere: inside the class, outside the class, and from child classes.
protected is more restrictive. It allows access inside the class itself and inside child classes that extend it. However, it blocks direct access from outside the class.
private is the most restrictive. It allows access only inside the class where it is defined. Not from outside. Not even from child classes.
The purpose of visibility is control. It protects internal state and forces interaction through methods when necessary. In real systems, most internal properties are not public. They are protected or private so that behavior remains predictable and controlled.