A complete PHP class contains seven syntax descriptions, PHP class seven syntax
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 constants not accessed Permission modifier const STUDENT = ' Tom '; Attribute public $stu _name; static property public static $stu _num = 1; Method Public Function Stufunction () {echo ' non_static_function ', '
'; }//static method public static function Static_stufunction () {echo ' static_function ', '
'; }//constructor automatically calls public function __construct ($stu _name) {$this->stu_name = $stu _name when creating an object; Echo ' __construct ', '
'; }//destructors automatically call public function __destruct when destroying objects () {echo ' __destruct ', '
'; }}//Instantiate class object $object = new Student (' Tom '); Object Call Property Echo $object->stu_name, '
'; Object call static Property echo $object:: $stu _num, '
'; Class Call Static property Echo Student:: $stu _num, '
'; Use objects to invoke methods and static methods $object->stufunction (), respectively; $object->static_stufunction (); $object:: Stufunction (); $object:: Static_stufunction (); Use classes to invoke methods and static methods Student::stufunction (), respectively; Student::static_stufunction (); Class calls the class constant echo student::student, '
';
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.
http://www.bkjia.com/PHPjc/1011950.html www.bkjia.com true http://www.bkjia.com/PHPjc/1011950.html techarticle a complete PHP class contains seven syntax descriptions, seven syntax descriptions in PHP class seven syntax classes-Properties-static properties-Methods-static methods-class constants-constructors-destructors ...