简体   繁体   English

类常量的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.";
}

I get an exception on the row containing the const: 我在包含const的行上遇到异常:

Parse error: syntax error, unexpected '.', expecting ',' or ';' 解析错误:语法错误,意外的“。”,期望为“,”或“;” in /home/BZUMUL/prog.php on line X 在第X行的/home/BZUMUL/prog.php中

I was going to switch to heredoc but then I got too curious so I couldn't stop trying to solve it. 我本来打算改用Heredoc,但后来我感到好奇,因此无法停止尝试解决它。

According to Class Constants : 根据类常量

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. 因此,您不能将表达式用于常量值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM