A complete PHP class contains seven syntax descriptions, and php class seven syntax _ PHP Tutorial

Source: Internet
Author: User
A complete PHP class contains seven types of syntax descriptions, and php class seven types of syntax. A complete PHP class contains seven syntax descriptions, seven syntax descriptions in seven php syntax classes-attribute-static property-method-static method-class constant-constructor-destructor a complete PHP class contains seven syntax description, seven php syntaxes

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 ','
';} // Static method public static function static_stuFunction () {echo 'static _ function ','
';} // The constructor automatically calls public function _ construct ($ stu_name) {$ this-> stu_name = $ stu_name; echo' _ construct ','
';} // Automatically call public function _ destruct () {echo' _ destruct ','
';}} // Instantiate class object $ object = new Student ('Tom'); // call the property echo $ object-> stu_name ,'
'; // Static property echo $ object: $ stu_num ,'
'; // Class call static property echo Student: $ stu_num ,'
'; // 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 (); // class call class constant echo Student: STUDENT,'
';

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.

Seven Types of syntax descriptions in the topology class-attribute-static property-method-static method-class constant-constructor-destructor...

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.