Skip to main content

Explain public, private, protected functions and variables inside a class in PHP.

I'll define a variable as a property

public method or property this is the default and can be accessed anywhere
protected method or property that can be accessed by the class that declared it or that inherits the class
private method or property that can only be accessed by the class that declared it

 

Related articles