Seven syntax descriptions in a class
-Properties
-Static Properties
-Method
-Static method
-Class Constants
-Constructor Function
-destructor
<?PHPclassStudent {//The access rights of properties, methods, and functions in the class are (functions and methods are the same concept)/private protected protected public//class constants do not have access modifiers ConstSTUDENT = ' Tom '; //Properties Public $stu _name; //Static Properties Public Static $stu _num= 1; //Method Public functionstufunction () {Echo' Non_static_function ', ' <br/> '; } //Static Methods Public Static functionstatic_stufunction () {Echo' Static_function ', ' <br/> '; } //automatically called when the constructor creates an object Public function__construct ($stu _name) { $this->stu_name =$stu _name; Echo' __construct ', ' <br/> '; } //automatically called when a destructor destroys an object Public function__destruct () {Echo' __destruct ', ' <br/> '; } } //instantiating a Class object $object=NewStudent (' Tom ')); //Object Invocation Properties Echo $object->stu_name, ' <br/> '; //Object Call static property Echo $object::$stu _num, ' <br/> '; //class calls a static property EchoStudent::$stu _num, ' <br/> '; //invoking methods and static methods, respectively, using objects $object-stufunction (); $object-static_stufunction (); $object::stufunction (); $object::static_stufunction (); //invoking methods and static methods, respectively, using classesStudent::stufunction (); Student::static_stufunction (); //class calls class constants EchoStudent::student, ' <br/> ';
Summarize:
objects can call properties and static properties, and classes can only invoke static properties.
objects can call methods and static methods, and classes can call methods and static methods.
A complete PHP class contains seven syntax descriptions