Protected vs Private variables in PHP

Class variables in PHP come in different flavors:

Public: anyone either inside the class or outside can access them
Protected: only the specified class and subclasses can access them
Private: only the specified class can access them. Even subclasses will be denied access.

Tags:

One Response to “Protected vs Private variables in PHP”

  1. Noam says:

    Thanks!
    Please note that for the private property, subclasses aren’t denied – but only not inherit that property.
    trying to print out a parent’s private property by the subclass won’t return a fatal error – only an undefined.