时间:2021-07-01 10:21:17 帮助过:21人阅读
//error_reporting(0);
class A
{
public $db='OK';
private static $_instance;
public static function getInstance()
{
if(!(self::$_instance instanceof self)){
self::$_instance = new self;
}
return self::$_instance;
}
//维持find方法中this指针的写法不变
public function find()
{
echo $this->db;
}
}
class B extends A
{
static function ex()
{
self::getInstance()->find();
}
}
$b=new B();
$b->find();
echo "
";
//第二种方法
B::ex();
?>