* 1. Three elements of constants:
* 1.1 Once created, it cannot be deleted or modified;
* 1.2 Do not add the '$' character in the header
* 1.3 Global scope, use
directly without declaration in the function * 2. Create:
* 2.1 Function: define('CONST_NAME', expression);
* 2.2 Keyword: const contName = static scalar, can be used in classes, cannot be used in functions
* 2.3 Constant names: usually only use uppercase letters and underlines, such as: ROOT_PATH
* 3. Access:
* 3.1 Keyword echo direct access: echo const_name;
* 3.2 Function: constant('constant name');
* 3.3 Function: get_defined_constants (): Get all constants
* 4. Detection: defined('constant name')
//Create constants
define('SITE_NAME','Peter Zhu的博客'); //函数define创建 const COUNTRY ='中国'; //关键字const创建
//Access constants
echo SITE_NAME,COUNTRY; //关键字echo 访问 echo '<hr>'; echo constant('SITE_NAME'); //函数constant访问 echo constant('COUNTRY'); //函数constant访问 echo '<hr><pre class="brush:php;toolbar:false">';
//Get all constants defined by the system, including user-defined
print_r(get_defined_constants()); echo '<hr>';
//Detect constants
echo defined('SITE_NAME') ? '已定义' : '未定义'; //检测常量是否已声明