PHP Custom Global constants and class constants
/** * 1, define (name,value,case_insensitive) custom global constants, default case Sensitive * 2, Const defines class constants. * 3, the constant name do not use "$" * 4, the name of the constant all use uppercase letters. *///defines global constants Languagedefine (' LANGUAGE ', ' China '); Echo language;//languageecho language;//China//define Global constants Cndefine (' CN ', ' China ', TRUE) echo cn;//China echo cn;//China//define class constant classes Consttest{const VERSION = ' 1.0 '; function consttest () {//class internally using "Self:: constant name" Call, Cannot use $thisecho ' self::version= '. self::version;}} Instantiate Consttest, the purpose is to call the constructor new Consttest ();//External call class constant, through the "class name:: Constant name" directly called, do not need to instantiate. 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) checks if the constant for the name is defined. Echo defined (' CN ')? ' True ': ' false ';
?
Printing results:
Language China China China self::version=1.0 version=1.0 True |
?
http://huangqiqing123.iteye.com/blog/1921428
?