PHP code used to check whether the extension library or function is available

Source: Internet
Author: User
Tags imap
With the increase of the version, PHP functions become more and more perfect, and more available extension libraries and functions are available. Therefore, we should also consider the compatibility of versions when writing programs, you also need to check whether the extension Library is installed on the server (especially the virtual host. The functions described in this article are actually available in the PHP Manual. However, these functions are independent and difficult to find, so we will introduce them separately for easy reference.
1. get all available modules-get_loaded_extensions this function returns all loaded (available) modules.
Usage:

The code is as follows:


Print_r (get_loaded_extensions ());


2. obtain the available functions of the specified module-get_extension_funcs. This function returns all available functions of the specified module. The input parameter (module name) must be in lowercase.
Usage:

The code is as follows:


Print_r (get_extension_funcs ("gd "));


3. get all defined functions-get_defined_functions this function returns all defined functions, including built-in functions and user-defined functions.
Usage:

The code is as follows:


Function myrow ($ id, $ data ){
Return"$ Id$ Data\ N ";
}
$ Arr = get_defined_functions ();
Print_r ($ arr );


Output:

The code is as follows:


Array
(
[Internal] => Array
(
[0] => zend_version
[1] => func_num_args
[2] => func_get_arg
[3] => func_get_args
[4] => strlen
[5] => strcmp
[6] => strncmp
...
[1, 750] => bcscale
[751] => bccomp
)
[User] => Array
(
[0] => myrow
)
)


$ Arr ["internal"] is a built-in function, and $ arr ["user"] is a user-defined function.
4. check whether the specified function exists-function_exists. This function returns whether the specified function has been defined.
Usage:

The code is as follows:


If (function_exists ('imap _ open ')){
Echo "IMAP functions are available.
\ N ";
} Else {
Echo "IMAP functions are not available.
\ N ";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.