少し問題があります。ここにあります:
これは私のシングルトン抽象クラスです:
abstract class Singleton { protected static $_instance = NULL; /** * Prevent direct object creation */ final private function __construct() { $this->actionBeforeInstantiate(); } /** * Prevent object cloning */ final private function __clone() { } /** * Returns new or existing Singleton instance * @return Singleton */ final public static function getInstance(){ if(null !== static::$_instance){ return static::$_instance; } static::$_instance = new static(); return static::$_instance; } abstract protected function actionBeforeInstantiate(); }
その後、抽象レジストリクラスを作成します。
abstract class BaseRegistry extends Singleton { //... }
次に、セッションレジストリの時間です。
class BaseSessionRegistry extends BaseRegistry { //... protected function actionBeforeInstantiate() { session_start(); } }
最後のステップ:
class AppBaseSessionRegistryTwo extends BaseSessionRegistry { //... } class AppBaseSessionRegistry extends BaseSessionRegistry { //... }
テスト
$registry = AppBaseSessionRegistry::getInstance(); $registry2 =AppBaseSessionRegistryTwo::getInstance(); echo get_class($registry) . '|' . get_class($registry2) . '<br>';
出力:
AppBaseSessionRegistry|AppBaseSessionRegistry
私の期待は:
AppBaseSessionRegistry|AppBaseSessionRegistryTwo
なぜ私はそのような結果を得たのですか?そして、どうすればコードを作り直して、期待した結果を得ることができますか?
更新:フレームワークでこれを使用します。そして、ユーザーは私のBaseSessionRegistry
クラスを拡張し、自分のものを追加します。フレームワーククラス内でこれを解決したい