码迷,mamicode.com
首页 > Web开发 > 详细

PHP单例模式

时间:2014-08-27 14:29:17      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   cti   log   sp   

<?php

class OA {

    public static $oa = array();
    public static $config = array();

    public static function setConfig(array $config) {
        return self::$config = array_merge(self::$config, $config);
    }

    public static function user() {
        oa_import("user");
        if (!key_exists(‘user‘, self::$oa) || !is_object(self::$oa[‘user‘])) {
            self::$oa[‘user‘] = new user();
        }
        return self::$oa[‘user‘];
    }

}

调用方式:

<?php
  OA::setconfig($config);   OA::user()->get();
?>

 

PHP单例模式

标签:style   blog   color   io   ar   div   cti   log   sp   

原文地址:http://www.cnblogs.com/ideaphp/p/3939293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!