The member attributes of a class can be encapsulated, and the member methods can also be encapsulated. The so-called encapsulation is to use private keywords to modify attributes and methods. The encapsulated attributes and methods become private attributes and private methods, such private attributes and methods cannot be directly accessed and used by external objects. They can only be used inside the class, that is, they can only be accessed with $ this. Private methods are called by other internal methods, if you want external new objects to access private properties, you can declare a public method in the class. Generally, you do not need to declare it yourself, you can use the magic methods _ set and _ get. The magic methods are automatically called when needed. The magic methods both have a prefix consisting of two underscores. See the following example.
Class person {
Private $ name;
Private $ sex = "confidential ";
Function _ Get ($ proname ){
Return $ this-> $ proname;
}
}
$ P = new person;
Echo $ p-> sex;