<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## 靜態方法 原始的方式,盡可能把方法轉為靜態,一般用于對類依賴不高的方法 ``` namespace App\Lib; class Add { public static function add(int $a,int $b){ return $a+$b; } } ``` //調用 ``` Add::add(1, 2);//3 ``` ## 依賴注入 缺陷是沒有友好的代碼提示 ``` namespace App\Lib; class Add { public function add(int $a,int $b){ return $a+$b; } } ``` ``` 注入容器 \EasySwoole\Component\Di::getInstance()->set("add",\App\Lib\Add::class); //調用容器中的方法 $add = \EasySwoole\Component\Di::getInstance()->get("add"); $add->add(1,2);//3 ``` ## 單例模式 可對無法做靜態化的方法進行靜態調用,用于復雜方法 ``` namespace App\lib; class Redis{ // 重點需要引入提供的單例 trait use \EasySwoole\Component\Singleton; public $redis; private function __construct(){ if(!extension_loaded("redis")){ throw new \Exception("redis.io 文件不存在"); } try{ $this->redis = new \Redis(); $result = $this->redis->connect("127.0.0.1", 6379, 3); } catch (\Exception $e){ throw new \Exception("redis 服務器異常"); } if ($result===false){ throw new \Exception("redis connect is failed"); } } public function get($key){ if (empty($key)) { return ''; } return $this->redis->get($key); } public function set($key, $value){ return $this->redis->set($key, $value); } } ``` 調用 ``` \App\Lib\Add::getInstance()->add(1, 2);//3 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看