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:
- < ? PHP
- Class say_const{
- CHARSET = "China" ;
- Publice function Say_hello () {
- Echo Slef::charset;
- }
- }
- $ Const1 = New say_const () '
- $const 1- > Say_hello ();
- ?>
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 ...