Heim  >  Artikel  >  php教程  >  php检测函数是否存在函数 function_exists

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

WBOY
WBOYOriginal
2016-06-13 11:17:401431Durchsuche

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);
}


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn