0
對於我的項目,我寫了一個基本的控制器類:繼承類的另一種類型的
<?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類型的。有任何想法嗎?