PHP檢查庫或函數是否可用的方法

來源:互聯網
上載者:User

標籤:http   io   ar   問題   cti   代碼   ad   ef   

隨著版本的升高,PHP的功能也越來越完善,可用的擴充庫和函數也越來越多,因此,我們寫程式時也要考慮版本的相容問題,同時還要考慮伺服器(特別是虛擬機器主機)是否安裝了擴充庫。
本文介紹的函數其實是PHP手冊上本來就有的,但是由於這些函數獨立性較強,尋找不易,所以單獨介紹一下,方便查閱。
1. 擷取所有可用的模組 - get_loaded_extensions
該函數返回所有已經載入的(可用的)模組。
用法:
PHP代碼
print_r(get_loaded_extensions());  
2. 擷取指定模組的可用函數 - get_extension_funcs
該函數返回指定模組所有可用的函數。傳入的參數(模組名稱)必須是小寫
用法:
PHP代碼
print_r(get_extension_funcs(‘gd‘)); 
3. 擷取所有已經定義的函數 - get_defined_functions
該函數返回所有已經定義的函數,包括內建函數和使用者自訂函數。
用法:
PHP代碼
function myrow($id, $data){    
    return ‘<tr><th>$id</th><td>$data</td></tr> ‘;    
}     
$arr = get_defined_functions();    
print_r($arr);  
輸出:
PHP代碼
Array   
(   
    [internal] => Array   
        (   
            [0] => zend_version   
            [1] => func_num_args   
            [2] => func_get_arg   
            [3] => func_get_args   
            [4] => strlen  
            [5] => strcmp  
            [6] => strncmp  
            ...   
            [750] => bcscale   
            [751] => bccomp  
        )   
  
    [user] => Array   
        (   
            [0] => myrow   
        )   
   金光大道娛樂城
)  
其中 $arr[‘internal‘] 是內建函數, $arr[‘user‘] 是使用者自訂函數。
4. 檢查指定函數是否存在 - function_exists
該函數返回指定函數是否已經定義。
用法:
PHP代碼
if (function_exists(‘imap_open‘)) {    
    echo ‘IMAP functions are available.<br /> ‘;    
} else {    
    echo ‘IMAP functions are not available.<br /> ‘;    
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.