Introduction of PHP object-oriented access modifier
This article mainly explains "PHP object-oriented access modifier introduction", the explanation content in the article is simple and clear, easy to learn and understand, please follow the small series of ideas slowly in-depth, together to study and learn "PHP object-oriented access modifier introduction" bar!
There are three access modifiers in PHP:
public (public, default)
protected (protected)
private (private)
They can be used on class properties and methods (collectively called class members), respectively, to modify access rights for class members.
public (public, default)
In PHP 5, if a class does not have an access modifier specifying a member, the default is public access.
/*
The following two methods declare access permissions with the same effect
*/
function say(){};
publilc function say(){};
When a member of a class is declared as a public access modifier, that member can be accessed and manipulated by external code.
private (private)
Members defined as private are visible to all members within the class, with no access restrictions. Access is not allowed outside the class.
protected (protected)
Protected is a bit more complicated, being declared a protected member, allowing access only to subclasses of the class.
Access rights table:
access
public
protected
private
all
★
subclass
★
★
within-class
★
★
★
Thank you for reading, the above is the "PHP object-oriented access modifier introduction" content, after learning this article, I believe we have a deeper understanding of PHP object-oriented access modifier introduction this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!