How to view PHP const correctly

Source: Internet
Author: User

If we encounter a constant value that cannot be changed in actual programming, a constant is usually defined to use this constant value. Then we use

When defining a constant, we can use const to modify the constant. The constant modified with PHP const is a bit different from other constants, that is, do not use "$" before the constant name ", remember! Of course, this constant value cannot be modified. Once defined, it cannot be modified "manually" anywhere in the program. This is the same as the define definition, and the use of const to define it also complies with the naming rules of other constants-use uppercase letters.

Let's look at a small PHP const example:

 
 
  1. <? Php
  2. Class say_const {
  3. Const CHARSET = "China ";
  4. Publice function say_hello (){
  5. Echo slef: CHARSET;
  6. }
  7. }
  8. $ Const1 = new say_const ()'
  9. $ Const1-> say_hello ();
  10. ?>
  11.  

The above describes the usage of PHP const.


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.