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