我尝试使用另一个的内容初始化静态var,但似乎失败了。
class Hey {
static $user = "peter";
static $home = '/home'.Hey::$user;
// syntax error, unexpected T_VARIABLE, expecting T_STRING
为什么它会失败并且没有init-function或其他东西?
答案 0 :(得分:3)
class Hey {
static $user = "peter";
static $home;
}
Hey::$home = '/home'.Hey::$user;
或$ home是私有的:
class Hey {
static $user = "peter";
private static $home;
static function init(){self::$home = '/home'.self::$user;}
}
Hey::init();