<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國際加速解決方案。 廣告
                ## 重載(overloading) PHP所提供的 "重載" 是指動態地 "創建" 類屬性和方法。我們是通過魔術方法(magic methods)來實現的。 當調用當前環境下未定義或不可見的類屬性或方法時,重載方法會被調用。 本節后面將使用 "不可訪問屬性" 和 "不可訪問方法" 來稱呼這些未定義或不可見的類屬性或方法。 所有的重載方法都必須被聲明為 `public` > **Note:** PHP 中的 "重載" 與其它絕大多數面向對象語言不同。傳統的"重載"是用于提供多個同名的類方法,但各方法的參數類型和個數不同。 ### 屬性的重載 ``` public void __set(string $name, mixed $value) public mixed __get(string $name) public bool __isset(string $name) public void __unset(string $name) ``` * 在給不可訪問屬性賦值時,`__set()` 會被調用。 * 讀取不可訪問屬性的值時,`__get()` 會被調用。 * 當對不可訪問屬性調用 `isset()` 或 `empty()` 時,`__isset()` 會被調用。 * 當對不可訪問屬性調用 `unset()` 時,`__unset()` 會被調用。 ``` <?php class MyClass { private $data = array(); public function __set($key, $val) { $this->data[$key] = $val; } public function __get($key) { if (isset($this->data[$key])) { return $this->data[$key]; } return null; } public function __isset($key) { if (isset($this->data[$key])) { return true; } return false; } public function __unset($key) { unset($this->data[$key]); } } $obj = new MyClass(); $obj->name = 'kate green'; echo "{$obj->name}" . PHP_EOL; ?> ``` ### 方法重載 ``` public mixed __call(string $name, array $arguments) public static mixed __callStatic(string $name , array $arguments) ``` * 在對象中調用一個不可訪問方法時,`__call()` 會被調用。 * 在靜態上下文中調用一個不可訪問方法時,`__callStatic()` 會被調用。 ``` <?php class MyClass { public function __call($name, $arguments) { echo "Calling object method '{$name}' " . implode(', ', $arguments). PHP_EOL; } public static function __callStatic($name, $arguments) { echo "Calling static method '{$name}' " . implode(', ', $arguments). PHP_EOL; } } $obj = new MyClass(); $obj->run('in object context'); MyClass::run('in static context'); ?> ```
                  <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>

                              哎呀哎呀视频在线观看