search
Homephp教程php手册PHP检查库或函数是否可用的方法

PHP检查库或函数是否可用的方法

Jun 13, 2016 am 10:38 AM
phpfunctionFunctionCanLibraryExpandmethodexamineVersionuseofalong with

随着版本的升高,PHP的功能也越来越完善,可用的扩展库和函数也越来越多,因此,我们写程序时也要考虑版本的兼容问题,同时还要考虑服务器(特别是虚拟主机)是否安装了扩展库。

本文介绍的函数其实是PHP手册上本来就有的,但是由于这些函数独立性较强,查找不易,所以单独介绍一下,方便查阅。

1. 获取所有可用的模块 - get_loaded_extensions 该函数返回所有已经加载的(可用的)模块。

用法:

print_r(get_loaded_extensions());

2. 获取指定模块的可用函数 - get_extension_funcs 该函数返回指定模块所有可用的函数。传入的参数(模块名称)必须是小写

用法:

print_r(get_extension_funcs("gd"));

3. 获取所有已经定义的函数 - get_defined_functions  该函数返回所有已经定义的函数,包括内置函数和用户自定义函数。

用法:

function myrow($id, $data){
return "

$id $data ";
}
$arr = get_defined_functions();
print_r($arr);

输出:

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  该函数返回指定函数是否已经定义。

用法:

if (function_exists(imap_open)) {
echo "IMAP functions are available.
";
} else {
echo "IMAP functions are not available.
";
}
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.