单例模式设计

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();

你可能感兴趣的:(php)