PHP Encapsulation 

(Object Oriented PHP)

Encapsulation allows a class to define what behavior & properties the external world is able to access within a class or objects. There are three modifiers, AKA assessors, that define how a class encapsulates its self from the perspective of the outside world.

The first accessor is public. The outside world is able to access public properties and public functions.

The second accessor is protected. Protected Properties and functions with a protected modifier are only accessible internally. Child classes inherit protected properties.

The third accessor is private. Private properties are only accessible internally and are NOT inherited by child classes. 


Anything with access to the object can use the property or function


Any internal functions can access the property or function and the protected property will be inherited by child classes.


Only the class itself can access the property or function, private properties or functions will NOT be inherited by children.