我正试图创建一个小枚举,但我被卡住了:为什么这不起作用?
class.LayoutParts.hp:
<?php
class LayoutParts {
const MAIN = 1;
const FOOTER = 2;
}
?>
class.SupportedLayouts.hp:
<?php
class SupportedLayouts {
const MAIN = LayoutParts::MAIN;
const MAIN_FOOTER = LayoutParts::MAIN.LayoutParts::FOOTER;
}
?>
结果显示以下消息:
Parse error: syntax error, unexpected '.', expecting ',' or ';' in /*****/class.SupportedLayouts.php on line 4
谢谢你的帮助!
问候,Flo
.
是一个运算符,使LayoutParts::MAIN.LayoutParts::FOOTER;
成为一个语句,这在const
或属性声明中是不允许的。
参见此处
值必须是常量表达式,而不是(例如)变量、属性、数学运算的结果或函数调用。