Phpself, $ this, const, static,-& amp; gt; usage _ PHP Tutorial

Source: Internet
Author: User
Use of phpself, $ this, const, static,-& amp; gt. Summary. When the internal method of the class accesses the attributes declared as const and static, use the form of self ::$ name. Note that the declarative format of the const attribute is constPI3.14, which is summarized today.
When the internal method of the class accesses the attributes declared as const and static, use the form of self ::$ name. Note the declarative format of the const attribute. const PI = 3.14 instead of const $ PI = 3.14.

The code is as follows:


Class clss_a {

Private static $ name = "static class_a ";

Const PI = 3.14;
Public $ value;

Public static function getName ()
{
Return self: $ name;
}
// This statement is incorrect. the static method cannot access non-static attributes.
Public static function getName2 ()
{
Return self: $ value;
}
Public function getPI ()
{
Return self: PI;
}


}


Note that if the class method is static, the Accessed attribute must also be static.
When the internal method access of the class is not declared as const or static, use the form of $ this-> value = 'class _.

Bytes. When the internal method of the class accesses the attributes declared as const and static, use the form of self ::$ name. Note that the declarative format of the const attribute, const PI = 3.14, and...

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.