PHP Access Modifier-Tutorialpath

PHP Access Modifier
PHP Access Modifier

Access Specifiers in PHP

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

Public: Class members declared public can be accessed everywhere.

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

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

 

Public Access modifier

Public Access modifier is open to use and access inside the class definition as well as outside the class definition.

 

public access modifier
public access modifier

Output:

public access modifier output
public access modifier output

Protected access modifier

Protected is only accessible within the class in which it is defined and its parent or inherited classes.

protected access modifier
protected access modifier

Output:

protected access modifier output
protected access modifier output

Private access modifier

Private is only accessible within the class that defines it.( it can’t be access outside the class means in inherited class).

private access modifier Example
private access modifier Example

Output:

 

Private Access Modifier
Private Access Modifier

2 thoughts on “PHP Access Modifier-Tutorialpath

Leave a Reply

Your email address will not be published.