Everyone should know that define and const are constants in PHP, so how much do you know about them? This article mainly and everyone to share PHP define and the difference between the const detailed, hope to help everyone.
The understanding of constants:
The constant is preceded by a dollar sign ($);
Constants can only be defined with the Define () function, not through assignment statements;
Constants can be defined and accessed anywhere, regardless of the scope of the variable;
Once a constant is defined, it cannot be redefined or undefined;
The value of a constant can only be scalar.
The difference between constant definitions:
Use of const |
use of define |
Const for the definition of a class constant |
Define cannot be used for definitions of class constants and can be used for global constants. |
Constants cannot be defined within a function, within loops, and within an if statement with Const. |
Define can |
Const uses a common constant name |
Define can use an expression as a name |
Const can only accept static scalar |
Define can take any expression |
Const-defined constants are case-sensitive |
Define can specify case sensitivity by using the third argument, true for case insensitivity. |