类常量的PHP表达式 [英] PHP expression for class constant
问题描述
我正在尝试弄清楚为什么我会得到此代码并出现异常。
I'm trying to figure out why I get and exception with this code.
class Test {
const test = "Two " .
"rows.";
}
我在包含const的行上遇到异常:
I get an exception on the row containing the const:
解析错误:语法错误,在
/home/BZUMUL/prog.php中出现意外的'。',期望为','或';' X行
Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/BZUMUL/prog.php on line X
我打算切换到heredoc,但是后来我变得很好奇,所以我迫不及待想要解决它。 / p>
I was going to switch to heredoc but then I got too curious so I couldn't stop trying to solve it.
推荐答案
根据类常量:
该值必须是常量表达式,而不是变量,属性,数学运算或函数调用的结果。
The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.
因此,不能将表达式用作常数值。
So you cannot use an expression for the constant value.
这篇关于类常量的PHP表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!