A complete PHP class contains seven syntax descriptions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.