PHP checks the code for whether an extension library or function is available
- 2020-03-31 20:32:27
- OfStack
In fact, the functions introduced in this article are already in the PHP manual, but because of the strong independence of these functions, not easy to find, so a separate introduction, easy to consult.
Get_loaded_extensions this function returns all the (available) modules that have been loaded.
Usage:
Get_extension_funcs this function returns all available functions of the specified module. The parameters passed in (module name) must be lowercase
Usage:
Get_defined_functions this function returns all defined functions, both built-in and user-defined.
Usage:
Output:
Where $arr["internal"] is a built-in function, and $arr["user"] is a user-defined function.
Checks whether the specified function exists -function_exists the function returns whether the specified function is defined.
Usage:
Get_loaded_extensions this function returns all the (available) modules that have been loaded.
Usage:
print_r(get_loaded_extensions());
Get_extension_funcs this function returns all available functions of the specified module. The parameters passed in (module name) must be lowercase
Usage:
print_r(get_extension_funcs("gd"));
Get_defined_functions this function returns all defined functions, both built-in and user-defined.
Usage:
function myrow($id, $data){
return "<tr><th>$id</th><td>$data</td></tr>n";
}
$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
)
)
Where $arr["internal"] is a built-in function, and $arr["user"] is a user-defined function.
Checks whether the specified function exists -function_exists the function returns whether the specified function is defined.
Usage:
if (function_exists('imap_open')) {
echo "IMAP functions are available.<br />n";
} else {
echo "IMAP functions are not available.<br />n";
}