久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      PHP鏈?zhǔn)秸{(diào)用怎么實(shí)現(xiàn)?

      PHP鏈?zhǔn)秸{(diào)用的實(shí)現(xiàn)方法:1、使用魔法函數(shù)【_call】結(jié)合【call_user_func】來實(shí)現(xiàn);2、使用魔法函數(shù)【_call】結(jié)合【call_user_func_array】來實(shí)現(xiàn);3、不使用魔法函數(shù)【_call】來實(shí)現(xiàn)。

      PHP鏈?zhǔn)秸{(diào)用怎么實(shí)現(xiàn)?

      PHP鏈?zhǔn)秸{(diào)用的實(shí)現(xiàn)方法:

      方法一、使用魔法函數(shù)__call結(jié)合call_user_func來實(shí)現(xiàn)

      思想:首先定義一個字符串類StringHelper,構(gòu)造函數(shù)直接賦值value,然后鏈?zhǔn)秸{(diào)用trim()strlen()函數(shù),通過在調(diào)用的魔法函數(shù)__call()中使用call_user_func來處理調(diào)用關(guān)系,實(shí)現(xiàn)如下:

      <?php class StringHelper  {   private $value;   function __construct($value)   {     $this->value = $value;   }   function __call($function, $args){     $this->value = call_user_func($function, $this->value, $args[0]);     return $this;   }   function strlen() {     return strlen($this->value);   } } $str = new StringHelper(" sd f 0"); echo $str->trim('0')->strlen();

      終端執(zhí)行腳本:

      php test.php  8

      方法二、使用魔法函數(shù)__call結(jié)合call_user_func_array來實(shí)現(xiàn)

      <?php class StringHelper  {   private $value;   function __construct($value)   {     $this->value = $value;   }   function __call($function, $args){     array_unshift($args, $this->value);     $this->value = call_user_func_array($function, $args);     return $this;   }   function strlen() {     return strlen($this->value);   } } $str = new StringHelper(" sd f 0"); echo $str->trim('0')->strlen();

      說明:

      array_unshift(array,value1,value2,value3...)

      array_unshift() 函數(shù)用于向數(shù)組插入新元素。新數(shù)組的值將被插入到數(shù)組的開頭。

      call_user_func()call_user_func_array都是動態(tài)調(diào)用函數(shù)的方法,區(qū)別在于參數(shù)的傳遞方式不同。

      方法三、不使用魔法函數(shù)__call來實(shí)現(xiàn)

      只需要修改_call()trim()函數(shù)即可:

      public function trim($t) {   $this->value = trim($this->value, $t);   return $this; }

      重點(diǎn)在于,返回$this指針,方便調(diào)用后者函數(shù)。

      相關(guān)學(xué)習(xí)推薦:PHP編程從入門到精通

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號