A complete PHP class contains seven syntax instructions, PHP class seven syntax _php tutorial

Source: Internet
Author: User

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 ...

  • 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.