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类型的。有任何想法吗?