The difference and connection between const and static in PHP

Source: Internet
Author: User

1.const is a constant in a class, define to define constants
2.const can only modify the properties of a class, cannot decorate a method of a class, static can modify a property, or you can modify a method
Both 3.const and static belong to the class itself, not to the class instance after new. In-class Access uses the self::, outside of the class using the class name:: To access; $this in a class refers to the class instance itself, and const and static belong to the class itself, so it cannot be accessed with $this
4.self::name refers to Const,self:: $name refers to the static;const is a constant, is not required by the variable symbol. Static modified variable, requires a variable character.
5.const once defined cannot be changed, static modified variables can be changed
The ordinary members and methods of the class cannot be used in the 6.static method; it is well understood that when a static method is called, it is not certain that the class has not been instantiated. The static property and the static method can be used in the normal method of the class.

The difference and connection between const and static in PHP

Related Article

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.