PHP constants among its statement

Constant features:

1, using the define () function to define the constant, after PHP 5.3, may be used const keyword define constants outside the class definition. If the constant is defined, it can never be changed or undefined. 

2, containing only the constant scalar data (boolean, integer, float, and string). You can define resource constants, but should be avoided, as it will cause unpredictable results. 

3, can be obtained by simply specifying its name value constants and variables, constants can not use the $ sign in front.

4, if the name of the constant is dynamic, also use the function constant () to get the value of the constant. With get_defined_constants () to get a list of all defined constants. 

5, constants can be defined and accessed anywhere without worrying about whether the scope of variables.

 

Declare constants:

? < PHP
 the DEFINE ( "CONSTANT", "the Hello world." );
 Echo  CONSTANT ; // "the Hello world." 
Echo  Constant ; // outputs "Constant" and issues an error message indicates a level 

// the following code in PHP 5.3. 0 after normal working 
const  CONSTANT = 'the Hello World' ;
 echo  CONSTANT ;
 ?>

From the micro-channel public number: Programming Society

Advanced programmers daily book, please pay attention!

Guess you like

Origin www.cnblogs.com/ai10999/p/11449474.html