PHP单例模式

时间:2014-08-27 14:29:17   收藏:0   阅读:369
<?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();
?>

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!