Home  >  Article  >  php教程  >  php检测函数是否存在函数 function_exists

php检测函数是否存在函数 function_exists

WBOY
WBOYOriginal
2016-06-13 11:17:401466browse

php检测函数是否存在函数 function_exists语法bool function_exists ( string $function_name )检查的定义的函数的列表,同时内置(内部)和用户定义的,为function_name。返回值  

php教程检测函数是否存在函数 function_exists
语法
bool function_exists ( string $function_name )
检查的定义的函数的列表,同时内置(内部)和用户定义的,为function_name。
返回值

返回true,如果function_name存在,是一个函数,否则返回false。
*/

if (function_exists('imap_open')) {
    echo "imap functions are available.www.bkjia.com
n";
} else {
    echo "imap functions are not available.
n";
}


//function_exists returns false on null and empty string:

if (function_exists('')) {
                echo "empty string function existsn";
        }

        if (function_exists(null)) {
                echo "null function existsn";
        }
  
//如果您使用suhosin.executor.func.blacklist而不是在你的php.ini disabled_functions,function_exists将返回true为功能。我用这个有与suhosin.executor.func.blacklist和disabled_functions相同beahviour:

function suhosin_function_exists($func) {
    if (extension_loaded('suhosin')) {
        $suhosin = @ini_get("suhosin.executor.func.blacklist");
        if (empty($suhosin) == false) {
            $suhosin = explode(',', $suhosin);
            $suhosin = array_map('trim', $suhosin);
            $suhosin = array_map('strtolower', $suhosin);
            return (function_exists($func) == true && array_search($func, $suhosin) === false);
        }
    }
    return function_exists($func);
}


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