There are two methods to create a class:
1. Declare a method name with the same class name in the class (PhP4, not recommended ).
2. Declare a _ construct () method.
Because the constructor is automatically called after the object is created, the constructor is used to initialize the member attributes of the class (assign values );
Class person {
VaR $ name;
VaR $ age;
VaR $ sex;
Function _ construct ($ A = "", $ B = 100, $ c = "male") {// assign an initial value to the parameter variable, because a warning is reported if no value is transferred when the new object is created.
$ This-> name = $;
$ This-> age = $ B;
$ This-> sex = $ C;
}
}
$ P1 = new person ("Kevin", 20, "man ");
$ P2 = new person ("Rose", 18, "female ");
Structure Method:
_ Destruct (); it is automatically called after the script runs. It is generally used to close resources, such as closing database resources and file resources. If the class object or object references such as ($ P1, $ P2) is deleted or released before the entire script is run. The Destructor will be called in advance or called immediately,