私のプロジェクトでは、基本的なコントローラークラスを作成しました。
<?php
   abstract class Controller
   {
      static $__instance = null;
      protected function __construct()
      {
      }
      final private function __clone()
      {
      }
      public static function getInstance()
      {
         $class = get_called_class();
         return self::$__instance ? self::$__instance : (self::$__instance = new $class());
      }
   }
?>
これで、すべてのコントローラーがこのコントローラーから継承します。
このような:
<?php
   include_once 'model/page.php';
   include_once 'view/page.php';
   class PageController extends Controller
   {
      private $m_model = null;
      private $m_view = null;
      private $m_id;
      protected function __construct()
      {
         parent::__construct();
         $this->m_id = uniqid();
         $this->m_model = new PageModel();
         $this->m_view = new PageView();
      }
      public function preparePage()
      {
         echo 'Hello';
      }
   }
?>
そして私のindex.phpで私はこれを手に入れました:$ user = UserController :: getInstance(); $ page = PageController :: getInstance(); var_dump($ page);
問題はvar_dump($page)、変数$ pageがUserControllerのタイプであることを示していることですが、なぜですか?タイプはPageControllerである必要があります。何か案は?