【发布时间】:2011-04-28 00:37:08
【问题描述】:
这是我想做的事情:
class Test {
public static $test = 'boo';
}
class Two extends Test {
public static $test = parent::$test.'hoo';
}
// Two::$test == 'boohoo'
嗯,特别是结合 2 个数组,但这说明了这一点。
有可能吗?
【问题讨论】:
这是我想做的事情:
class Test {
public static $test = 'boo';
}
class Two extends Test {
public static $test = parent::$test.'hoo';
}
// Two::$test == 'boohoo'
嗯,特别是结合 2 个数组,但这说明了这一点。
有可能吗?
【问题讨论】:
这是不可能的,因为您在声明变量时无法评估任何内容。
类似:
class A {
$seconds_in_a_day = 60*60*24; // invalid
$seconds_in_a_day2 = 86400; // sour but valid
}
甚至无效。
你可以把它移到构造函数中。
public function __construct() {
self::$test = parent::$test.'hoo';
}
除此之外.. 只是不要这样做。为您未来的自己节省大量工作并找到另一个更直观的解决方案:P
【讨论】: