Rumah >pembangunan bahagian belakang >tutorial php >深入研究PHP检查函数可用的方法_PHP教程
我们在使用
PHP检查函数可用1. 获取所有可用的模块 - get_loaded_extensions
该函数返回所有已经加载的(可用的)模块。
用法:
print_r(get_loaded_extensions());
PHP检查函数可用2. 获取指定模块的可用函数 - get_extension_funcs
该函数返回指定模块所有可用的函数。传入的参数(模块名称)必须是小写
用法:
print_r(get_extension_funcs("gd"));
PHP检查函数可用3. 获取所有已经定义的函数 - get_defined_functions
该函数返回所有已经定义的函数,包括内置函数和用户自定义函数。
用法:
<ol class="dp-xml"> <li class="alt"><span><span>function myrow($id, $data){ </span></span></li> <li> <span>return "</span><span class="tag"><span class="tag-name">tr</span><span class="tag">></span><span class="tag"><span class="tag-name">th</span><span class="tag">></span><span>$id</span><span class="tag"></span><span class="tag-name">th</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span>$data</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"></span><span class="tag-name">tr</span><span class="tag">></span><span>n"; </span></span></span></span> </li> <li class="alt"><span>} </span></li> <li> <span>$</span><span class="attribute">arr</span><span> = </span><span class="attribute-value">get_defined_functions</span><span>(); </span> </li> <li class="alt"><span>print_r($arr); </span></li> </ol>
输出:
<ol class="dp-xml"> <li class="alt"><span><span>Array </span></span></li> <li><span>( </span></li> <li class="alt"> <span>[internal] =</span><span class="tag">></span><span> Array </span> </li> <li><span>( </span></li> <li class="alt"> <span>[0] =</span><span class="tag">></span><span> zend_version </span> </li> <li> <span>[1] =</span><span class="tag">></span><span> func_num_args </span> </li> <li class="alt"> <span>[2] =</span><span class="tag">></span><span> func_get_arg </span> </li> <li> <span>[3] =</span><span class="tag">></span><span> func_get_args </span> </li> <li class="alt"> <span>[4] =</span><span class="tag">></span><span> strlen </span> </li> <li> <span>[5] =</span><span class="tag">></span><span> strcmp </span> </li> <li class="alt"> <span>[6] =</span><span class="tag">></span><span> strncmp </span> </li> <li><span>... </span></li> <li class="alt"> <span>[750] =</span><span class="tag">></span><span> bcscale </span> </li> <li> <span>[751] =</span><span class="tag">></span><span> bccomp </span> </li> <li class="alt"><span>) </span></li> <li> <span>[user] =</span><span class="tag">></span><span> Array </span> </li> <li class="alt"><span>( </span></li> <li> <span>[0] =</span><span class="tag">></span><span> myrow </span> </li> <li class="alt"><span>) </span></li> <li><span>) </span></li> </ol>
其中 $arr["internal"] 是内置函数, $arr["user"] 是用户自定义函数。
PHP检查函数可用4. 检查指定函数是否存在 - function_exists
该函数返回指定函数是否已经定义。
用法:
<ol class="dp-xml"> <li class="alt"><span><span>if (function_exists('imap_open')) { </span></span></li> <li> <span>echo "IMAP functions are available.</span><span class="tag"><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>n"; </span></span> </li> <li class="alt"><span>} else { </span></li> <li> <span>echo "IMAP functions are not available.</span><span class="tag"><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>n"; </span></span> </li> </ol>