合集 const 下的文章

define ()和const ()的区别

用define定义的常量值可以为变量,而const定义的常量值不能是变量,只能是字面量或标量,包括整数,浮点数,布尔值,字符串。例: $price = 100;define('BOOK',$price);echo BOOK; //输出100$price = 100;const BOOK = $price;echo BOOK; //错误提示:Fatal error: Constant expression contains invalid operations in翻译:致命错误:常量表达式中包含无效的操作const可以声明类常量,而define不能。例:class Test1{const NAME ='测试';} echo Test1::NAME;//输出 测试 class Test1{define(NAME,'测试');}echo Test1::NAME;//错误提示:Parse error: syntax error, unexpected 'define' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST