Can I use string concatenation to define a class CONST in PHP?

前端 未结 5 1632
一个人的身影
一个人的身影 2020-11-30 09:54

I know that you can create global constants in terms of each other using string concatenation:

define(\'FOO\', \'foo\');
define(\'BAR\', FOO.\'bar\');  
echo         


        
5条回答
  •  渐次进展
    2020-11-30 10:15

    For class constants, you can't assign anything other than a constant expression. Quoting the PHP manual:

    "The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call. "

提交回复
热议问题