2018/03/07 daily One learn PHP constants Defind and const differences

Source: Internet
Author: User

What is a constant?

A literal understanding of the amount of non-change during the execution of a script.

What should be noted for defining a constant?

1: The constants are case sensitive, and the case of the error is not recognized as a constant.

2: Constants can only be scalar data, but also define resource constants, but defined, there will be some wonderful, unpredictable errors, so should be avoided as far as possible.

Scalar data: (Boolean,integer,float and string)

by Defind and const differences

1: Duplicate definition

1:defind repeating constants, constants will not be modified, PHP report a notification error;

Error:

          

Conclusion:

Although it does not affect the operation of the program, the problem should be reduced alone.

      1:const repeatedly defines constants, fatal errors.

Error:

          

2:Defind can not be used in the class, otherwise the fatal error is reported

Error:

          

    3:const can only be defined within a class and cannot be defined in a method, conditional statement

    4: Pick:

      Using const makes the code easy to read, and const itself is a language structure, and define is a function. In addition, the const is much faster to compile than define.

5: Correlation function

defined-checks if a constant exists for a name

constant-returns the value of a constant

Get_defined_constants -Returns an associative array of all constants

After the study, if in the encounter other, in addition.

2018/03/07 Daily Learn PHP constants Defind and const differences

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.