PHP detects whether a function exists function function_exists syntax bool function_exists (string $function_name) checks the list of defined functions, both built-in (internal) and user-defined, for function_name. return value
php tutorial to detect whether a function exists function_exists
Grammar
bool function_exists ( string $function_name )
Check the list of defined functions, both built-in (internal) and user-defined, for function_name.
Return value
Returns true if function_name exists and is a function, otherwise returns 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";
}
//If you use suhosin.executor.func.blacklist instead of disabled_functions in your php.ini, function_exists will return true for the function. I used this and had the same beahviour with suhosin.executor.func.blacklist and disabled_functions:
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);
}