我有一個被許多其他類繼承的抽象類。我想這樣做,而不是每次重新實例化(__construct())同一個類,只讓它初始化一次,並利用先前繼承的類的屬性。PHP不允許對象多次實例化
我在我的構建使用此:
function __construct() {
self::$_instance =& $this;
if (!empty(self::$_instance)) {
foreach (self::$_instance as $key => $class) {
$this->$key = $class;
}
}
}
這工作 - 那種,我能夠得到的屬性,並重新分配它們,但在此,我也想打電話給一些其他班級,但只有一次。
有關更好的方法去做這個的任何建議?
入住這裏 http://stackoverflow.com/questions/8856755/how-can-i-create-a-singleton-in-php – makriria
入住這裏 http://stackoverflow.com/questions/8856755/how-can-i-create-a-singleton-in-php – makriria
起初我以爲這是一個註冊模式,看到for-each循環。 –