class my{
protected static $obj;
public function __construct(){
}
public static function getInstace(){
if(self::$obj===null){
self::$obj = new self();
echo "init ";
}
return self::$obj;
}
public function getTitle(){
echo "I am is Title";
}
public function getContent(){
echo "I am is content";
}
}
$obj = my::getInstace();
$obj->getTitle();
$obj->getContent();
单例模式设计
最新推荐文章于 2021-12-06 18:38:04 发布