- <?php
- /**
- * <p>配置类,采用单例模式</p>
- */
- class sclass {
- private static $_sclass=null;
- private static $_ar_config = array();
- private function __construct(){
- }
- public static function getInstance(){
- if(self::$_sclass==null){
- self::$_sclass = new sclass();
- echo "=--1-1-1--1-";
- }
- return self::$_sclass;
- }
- public function getConfig($name){
- if(self::$_ar_config[$name]){
- return self::$_ar_config[$name];
- }
- return null;
- }
- public function setConfig($name,$val){
- self::$_ar_config[$name] = $val;
- }
- }
- ?>
- //引用方式
- <?php
- require('model/s.class.php');
- sclass::getInstance()->setConfig("aa",'111111');
- $str = sclass::getInstance()->getConfig('aa');
- ?>