A complete PHP class contains seven syntax descriptions, and php class seven syntax
Class Seven syntax descriptions
-Attributes
-Static attributes
-Method
-Static Method
-Class Constants
-Constructor
-Destructor
<? Php class Student {// The attributes, methods, and functions in the class have access permissions (functions and methods are the same concept) // private protected public // class constant does not have access permission modifier const STUDENT = 'Tom '; // attribute public $ stu_name; // static attribute public static $ stu_num = 1; // method public function stuFunction () {echo 'non _ static_function ',' <br/> ';} // static method public static function static_stuFunction () {echo 'static _ function', '<br/> ';} // when the constructor creates an object, it automatically calls public function _ construct ($ stu_name) {$ this-> stu_name = $ stu_name; echo '_ construct ', '<br/>';} // when the Destructor destroys an object, the public function _ destruct () {echo '_ destruct' is automatically called ', '<br/>' ;}}// instantiate Class object $ object = new Student ('Tom '); // call the property echo $ object-> stu_name, '<br/>'; // Static Property echo $ object: $ stu_num, '<br/>'; // class call Static Property echo Student :: $ stu_num, '<br/>'; // use an object to call methods and static methods, respectively. $ object-> stuFunction (); $ object-> static_stuFunction (); $ object :: stuFunction (); $ object: static_stuFunction (); // use classes to call methods and static methods respectively. Student: stuFunction (); Student: static_stuFunction (); // echo Student: STUDENT, '<br/> ';
Summary:
Objects can call attributes and static attributes. classes can only call static attributes.
Objects can call methods and static methods. classes can call methods and static methods.