摘要:<?php // new static 得到的单例分别为D,E和F。 class D { protected static $_instance = null; protected function __construct(){} protec
<?php
// new static 得到的单例分别为D,E和F。
class D
{
protected static $_instance = null;
protected function __construct(){}
protected function __clone()
{
//disallow clone
}
static public function getInstance()
{
if (static::$_instance === null) {
static::$_instance = new static();
}
return static::$_instance;
}
}
class E extends D
{
protected static $_instance = null;
}
class F extends D{
protected static $_instance = null;
}
$d = D::getInstance();
$e = E::getInstance();
$f = F::getInstance();
var_dump($d);
var_dump($e);
var_dump($f);
?>
批改老师:天蓬老师批改时间:2019-03-28 10:47:02
老师总结:你就是后期静态绑定, 用在静态继承的上下文环境中