久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放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. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      使用PHP反射機(jī)制獲取函數(shù)文檔

      反射 Reflection

      反射可以簡(jiǎn)單理解為掃描類的屬性、方法和注釋的能力。

      用法

      PHP 為我們提供了豐富的方法,使我們可以方便的使用。

      $reflect = new ReflectionClass('AppFoo'); $reflect->getMethods(); // 獲取方法的數(shù)組 $reflect->getDocComment(); // 獲取文檔注釋 ……

      應(yīng)用

      有時(shí)系統(tǒng)需要向用戶提供內(nèi)置方法文檔說(shuō)明來(lái)使用,那么我們則可以通過(guò) PHP 反射實(shí)現(xiàn)。

      創(chuàng)建內(nèi)置函數(shù)類

      class FooFunction{     /**      * 獲取當(dāng)前周周一時(shí)間戳      *      * @return false|string      */     public static function mondayTimeStamp(){         $targetTime = strtotime('now');         $w = date('w', $targetTime);         $w = ($w == 0 ? 7 : $w);         return mktime(0,0,0, date('m', $targetTime), date('d', $targetTime)-($w-1), date('Y', $targetTime));     }     /**      * 獲取當(dāng)前周周一日期      *      * @return false|string      */     public static function mondayDate(){         return date('Y-m-d', self::mondayTimeStamp());     } }

      掃描內(nèi)置函數(shù)類,生成文檔

      // 利用 PHP 反射 $reflect = new ReflectionClass('FooFunction'); $data = []; // 獲取類中的方法 $methods = $reflect->getMethods(); foreach ($methods as $method){     $methodName = $method->getName();     $methodDocStr = $reflect->getMethod($methodName)->getDocComment();     // 過(guò)濾方法注釋前面的(*)     $pattern = "/[@a-zA-Z\x{4e00}-\x{9fa5}]+.*/u";     preg_match_all($pattern, $methodDocStr, $matches, PREG_PATTERN_ORDER);     $data[] = [         'name' => $methodName,         'doc' => $matches[0]     ]; } echo json_encode($data);

      結(jié)果

      [     {         "name": "mondayTimeStamp",         "doc": [             "返回當(dāng)前周周一時(shí)間戳",             "@return false|string"         ]     },     {         "name": "mondayDate",         "doc": [             "返回當(dāng)前周周一日期",             "@return false|string"         ]     } ]

      推薦教程:《PHP教程》

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