Seven syntax descriptions in a class
-Properties
-Static properties
-Method
-Static method
-Class constants
-Constructor function
-destructor
<?php class Student { //classes have access to properties, methods, and functions (functions and methods are the same concept) //Private protected protected public //class constant does not have access permission modifiers ConstSTUDENT =' Tom ';//Properties Public $stu _name;//static properties 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/> '; }//constructor is called automatically when an object is created Public function __construct($stu _name) { $this->stu_name =$stu _name;Echo ' __construct ',' <br/> '; }//destructors are automatically called when destroying objects Public function __destruct() { Echo ' __destruct ',' <br/> '; } }//Instantiate class object $object=NewStudent (' Tom ');//Object invocation Properties Echo $object->stu_name,' <br/> ';//Object call static property Echo $object::$stu _num,' <br/> ';//Class Call static property EchoStudent::$stu _num,' <br/> ';//Use objects to invoke methods and static methods, respectively $object->stufunction ();$object->static_stufunction ();$object:: Stufunction ();$object:: Static_stufunction ();//Use classes to invoke methods and static methods, respectivelyStudent::stufunction (); Student::static_stufunction ();//Class calling Class constants EchoStudent::student,' <br/> ';
Summary: 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.
Seven syntax descriptions in the PHP class