Access Specifier in PHP

Access Specifier in PHP

Access specifier in php is part of encapsulation. Encapsulation can be achieve with the help of access specifier. Access specifier specifies the level of the access of properties and methods.

There are three Access Specifiers in PHP private, public protected. These keywords help you to define how methods and properties will be accessed by the user.

  • Private 
  • Public
  • Protected

Private:

Private Data member and member function that declared as private are not allowed to be called from outside the class. However, you can easily access these properties within the class

Public :

Any Data member and member function that declared as public or without any modifier are allowed to access these properties from inside or outside the class.

Protected:

It is a special type of modifier. If any property or method is declared as protected, you can only access these properties within the class and its subclass.

Scroll to Top