Php customizes global constants and class constants/*** 1. define (name, value, case_insensitive) customizes global constants. the default value is case sensitive. * 2. const defines class constants. * 3. do not use "$" * 4. do not use the constant name to allow php to customize global constants and class constants.
/*** 1. define (name, value, case_insensitive) customizes global constants. the default value is case sensitive. * 2. const defines class constants. * 3. do not use "$" * 4 before the constant name. generally, uppercase letters are used for the constant name. * /// Defines the global constant LANGUAGEdefine ('language ', 'China'); echo LANGUAGE; // languageecho language; // China // defines the global constant CNdefine ('cn ', 'China', TRUE); echo CN; // China echo cn; // China // definition class constant class ConstTest {const VERSION = '1. 0'; function ConstTest () {// class internal use "self: constant name" call, cannot use $ thisecho 'self: VERSION = '. self: VERSION ;}/// instantiate ConstTest to call the ConstTest () constructor. // call a class constant by using the class name :: the constant name is called directly without instantiation. Echo 'version = '. (ConstTest: VERSION); echo'
'; // Array get_defined_constants ([bool $ categorize = false]) returns all defined constants // print_r (get_defined_constants (true); // bool defined (string $ name) check whether the constant of the name has been defined. Echo defined ('cn ')? 'True': 'false ';
?
Print result:
Language China China China Self: VERSION = 1.0 VERSION = 1.0 True |
?
Http://huangqiqing123.iteye.com/blog/1921428
?