Access Specifiers in PHP

There are 3 types of Access Specifiers available in PHP, Public, Private and Protected.

Public - class members with this access modifier will be publicly accessible from anywhere, even from outside the scope of the class.

Private - class members with this keyword will be accessed within the class itself. It protects members from outside class access with the reference of the class instance.

Protected - same as private, except by allowing subclasses to access protected superclass members.

EXAMPLE 1: Public

Output:

Access Specifiers in PHP

EXAMPLE 2: Private

Output:

Access Specifiers in PHP

EXAMPLE 3: Protected

Output:

Access Specifiers in PHP

EXAMPLE 4: Public,Private and Protected

Output:

Access Specifiers in PHP
Next Topic#




Contact US

Email:[email protected]

OOPs Access Specifiers
10/30