PHP note: Detailed description based on object-oriented design. Public indicates Global, which can be accessed by external sub-classes inside the class. copy the code as follows :? PhpclassTest {public $ nameJanking, $ sexmale, $ age23; function _ construct () {echo public indicates global, and can be accessed by external subclass inside the class;
The code is as follows:
Class Test {
Public $ name = 'janking ',
$ Sex = 'male ',
$ Age = 23;
Function _ construct (){
Echo $ this-> age .'
'. $ This-> name .'
'. $ This-> sex .'
';
}
Function func (){
Echo $ this-> age .'
'. $ This-> name .'
'. $ This-> sex .'
';
}
}
$ P = new Test ();
Echo'
';
$ P-> age = 100;
$ P-> name = "Rainy ";
$ P-> sex = "female ";
$ P-> func ();
?>
Public
Private indicates private, which can only be used inside the class;
The code is as follows:
Class Test {
Private $ name = 'janking ',
$ Sex = 'male ',
$ Age = 23;
Function _ construct (){
$ This-> funcOne ();
}
Function func (){
Echo $ this-> age .'
'. $ This-> name .'
'. $ This-> sex .'
';
}
Private function funcOne (){
Echo $ this-> age .'
'. $ This-> name .'
'. $ This-> sex .'
';
}
}
$ P = new Test ();
Echo'
';
$ P-> func ();
$ P-> age = 100; // Cannot access private property Test: $ age
$ P-> name = "Rainy"; // Cannot access private property Test: $ name
$ P-> sex = "female"; // Cannot access private property Test: $ female
$ P-> funcOne (); // Call to private method Test: funcOne () from context''
?>
Private
Protected indicates that it is protected and can be accessed only in the current class or subclass or parent class; magic methods related to Encapsulation:
_ Set (): The method automatically called when the property value of a private member is directly set.
_ Get (): The method automatically called when the private member attribute value is directly obtained.
_ Isset (); this method is automatically called when the isset directly checks whether the private attributes in the object are stored.
_ Unset (); is the method automatically called When unset directly deletes the private attribute of an object.
The http://www.bkjia.com/PHPjc/327164.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327164.htmlTechArticlepublic represents the global, and the class's internal external subclass can be accessed; the code is as follows :? Php class Test {public $ name = 'janking', $ sex = 'male', $ age = 23; function _ construct () {echo...