亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php 使用 __call實現(xiàn)重載功能示例

 更新時間:2019年11月18日 10:00:32   作者:ztblog  
這篇文章主要介紹了php 使用 __call實現(xiàn)重載功能,結合實例形式分析了PHP使用__call實現(xiàn)重載的相關操作技巧,需要的朋友可以參考下

本文實例講述了php 使用 __call實現(xiàn)重載功能。分享給大家供大家參考,具體如下:

<?php
/**
 * Created by PhpStorm.
 * User: funco
 * Date: 17-6-9
 * Time: 下午1:39
 */
class MulStat
{
  // showClass 可以接受0個參數(shù)
  private function showClass() {
    echo "this is class ".__CLASS__;
  }

  // showString 可以接受一個參數(shù)
  private function showString($str) {
    echo "string is ".$str;
  }

  // __call方法 可以獲取實例化對象調用的成員函數(shù)名和向該被調函數(shù)傳遞的參數(shù)個數(shù)
  public function __call($name, $args) {
    // 先判斷要調用的函數(shù)名$name
    if($name == "showInfo"){
      // 然后可以根據(jù)參數(shù)($args)數(shù)量判斷調用哪個成員函數(shù)
      switch(count($args)) {           // count可以計算數(shù)組元素個數(shù)
        case 0:
          $this->showClass();break;
        case 1:
          $this->showString($args[0]);break;
      }// switch
    }// if
  }
}

//實例化MulStat類
$mulStat = new MulStat();

echo "\$mulStat->showInfo(\"funco 小風\"):\n";
$mulStat->showInfo("funco 小風");

// 兩次換行 便于觀察結果
echo "\n\n";

echo "\$mulStat->showInfo():\n";
$mulStat->showInfo();

運行結果:

$mulStat->showInfo("funco 小風"):
string is funco 小風

$mulStat->showInfo():
this is class MulStat

更多關于PHP相關內容感興趣的讀者可查看本站專題:《php面向對象程序設計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論