Seven syntax descriptions in the PHP class

Source: Internet
Author: User

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

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.