Teach you the correct view of PHP const_php tutorial

Source: Internet
Author: User
Tags define definition
If we encounter a constant value that cannot be changed in actual programming, a constant is usually defined to use the constant value. Then we're going to use it.

When defining a constant, we can use the const to modify the constant, and the constant that uses the const modifier of PHP is a bit different from the constant: Don't use "$" before the constant name, remember! Of course, this constant value can not be modified, once defined can not be anywhere in the program "artificial" modification. This is the same as using the define definition, and there is a naming convention that uses const to define and, of course, abide by other constants-using letters of large characters.

Let's look at a small php const example:

 
  
  
  1. < ? PHP
  2. Class say_const{
  3. CHARSET = "China" ;
  4. Publice function Say_hello () {
  5. Echo Slef::charset;
  6. }
  7. }
  8. $ Const1 = New say_const () '
  9. $const 1- > Say_hello ();
  10. ?>

The above is the specific usage of PHP const introduction.


http://www.bkjia.com/PHPjc/446024.html www.bkjia.com true http://www.bkjia.com/PHPjc/446024.html techarticle If we encounter a constant value that cannot be changed in actual programming, a constant is usually defined to use the constant value. Then we use the time to define a constant ...

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