我的班级中有示例代码:
public $themePath = "layouts/inbox/";
public $theme = $this->themePath."theme-limitless.";
public $inboxView = $this->theme."inbox";
这里我的代码不起作用。我必须将我的主题名称保存在一个var和另一个var中的主题路径中,并使用主题名称使用视图。现在我有错误:
Constant expression contains invalid operations:
public $theme = $this->themePath."theme-limitless."; // Error line
通常我必须在var $inboxView
中获取路径:
$inboxView = "layouts/inbox/theme-limitless.inbox";
答案 0 :(得分:1)
您可以在__construct
方法中初始化类属性:
class MyClass
{
public $themePath = "layouts/inbox/";
public $theme;
public $inboxView;
function __construct() {
$this->theme = $this->themePath . "theme-limitless.";
$this->inboxView = $this->theme . "inbox";
}
}