PHP OOP - Access Modifiers
PHP - Access Modifiers
Access modifiers contains properties and methods which control where they can be accessed.
There are three access modifiers:
- public - the property or method can be accessed from everywhere. This is default
- protected - the property or method can be accessed within the class and by classes derived from that class.
- private - the property or method can ONLY be accessed within the class.
Public:
A public member is accessible from even outside the class. Anyone can read or modify the value of a public member.
Private:
A private member is only accessible by the class itself. It cannot be accessed outside the class.
Protected:
A protected member is accessible only by the class or the child classes.