Home >Backend Development >PHP Tutorial >Simple difference comparison and usage introduction between Public&Private&Protect in php
This article brings you a simple comparison and usage introduction between Public&Private&Protect in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
public [Public]
can be called by other classes and objects anywhere in the program (inside the class, outside the class). Subclasses can inherit and use all public members of the parent class.
Private [Private]
Variables and methods modified by private can only be called and modified inside the class where they are located, and cannot be accessed outside the class. Neither is possible in subclasses.
If called directly, an error will occur.
Protect [Protected]
Class members modified with protected can be called in this class and subclasses, but cannot be called elsewhere.
Related recommendations:
public, private, protected in php5
The difference between public, private, and protected in php class , and examples
The above is the detailed content of Simple difference comparison and usage introduction between Public&Private&Protect in php. For more information, please follow other related articles on the PHP Chinese website!