返回静态绑定技术调......登陆

静态绑定技术调用

弦知音2019-03-28 10:39:40317
<?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);

?>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送