PHP learning and PHP Learning
Class:
1. Similar objects are classified into a class by means of classification.
2. The class defines the same attributes and methods of these similar objects.
3. The class object is called an instance of the class.
4. class attributes and methods are collectively called class members.
Implement through a class
1. How to define a class
2. How to instantiate class objects
3. How to call class methods
<? Php // class definition starts with the keyword class, followed by the class name class ceshi {// defines the attribute public $ a = "ceshi"; // defines the method, function ceshifunction () {echo "this is a test method" ;}}// class instantiation $ ceshi = new ceshi (); // obtain the attribute value echo $ ceshi->. "<br/>"; // obtain the class method echo $ ceshi-> ceshifunction (). "<br/>";?>4. Constructor
5. destructor
<? Php // class definition starts with the keyword class, followed by the class name class ceshi {// defines the attribute public $ a = "ceshi "; // The constructor will directly execute this function when calling the class. You can pass parameters in function _ construct ($ info) {$ this-> a = $ info} // destructor. When the execution ends, when the variable is null, run the // destructor, which is usually used to clean up the resource function _ destruct () {echo "program execution ends ". $ this-> a;} // define the method. function ceshifunction () {echo "this is a test method ";}} // class instantiation $ ceshi = new ceshi ('another variable '); // obtain the attribute value echo $ ceshi->. "<br/>"; // You can trigger the Destructor $ ceshi = null by setting the variable to null. // obtain the class Echo $ ceshi-> ceshifunction (). "<br/>";?>