Home  >  Article  >  Backend Development  >  PHP method to check whether a library or function is available_PHP tutorial

PHP method to check whether a library or function is available_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:39:24828browse

As the version increases, PHP’s functions become more and more complete, and more and more extension libraries and functions are available. Therefore, we must also consider version compatibility issues when writing programs, and we must also consider the server. (Especially virtual host) Whether the extension library is installed.

The functions introduced in this article are actually in the PHP manual. However, because these functions are highly independent and difficult to find, they are introduced separately for easy reference.

1. Get all available modules - get_loaded_extensions This function returns all loaded (available) modules.

Usage:

print_r(get_loaded_extensions());

2. Get the available functions of the specified module - get_extension_funcs This function returns all available functions of the specified module. The passed-in parameter (module name) must be lowercase

Usage:

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:

function myrow($id, $data){
return "$id$data ";
}
$arr = get_defined_functions();
print_r($arr);

Output:

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
)

)

Among them, $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:

if (function_exists(imap_open)) {
echo "IMAP functions are available.
";
} else {
echo "IMAP functions are not available.
";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486309.htmlTechArticleAs the version increases, the functions of PHP become more and more complete, and the available extension libraries and functions become more and more complete. There are more and more, so when we write programs, we must also consider version compatibility issues, and also consider...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn