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:
- <? Php
- Class say_const {
- Const CHARSET = "China ";
- Publice function say_hello (){
- Echo slef: CHARSET;
- }
- }
- $ Const1 = new say_const ()'
- $ Const1-> say_hello ();
- ?>
-
The above describes the usage of PHP const.