PHP theorytheory 0/50 · 0%
OOP · easy

13. Visibility Modifiers

Controlling access to members.

public members are accessible from anywhere, protected members only from the class and its subclasses, and private members only from within the declaring class itself. Choosing the narrowest visibility that works enforces encapsulation.

Since PHP 7.4, typed properties can also be declared readonly-adjacent via visibility plus type hints for safer APIs.

Check your understanding

  1. 1. Which visibility allows access only within the declaring class?

  2. 2. Which visibility allows access from subclasses?