Access modifier in PHP

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

What are Access Modifiers ?

Access modifiers are object-oriented programming that is used to set the accessibility of classes, constructors, methods, and other members of php.
Using the access modifiers we can set the scope or accessibility of these classes, methods, constructors, and other members. 

There are three types of access modifier in PHP

  • public
  • protected
  • private

Public :- When we define class members as public, then they are accessible from anywhere, even from outside of the class scope.

eg:-

Protected: Class members declared protected can be accessed only within the class itself and by inheriting classes.

eg:-

Private: Class members declared as private may only be accessed by the class that defines the member.

eg:-