PHP detects whether a function exists function_exists_PHP tutorial

WBOY
Release: 2016-07-20 11:01:26
Original
1217 people have browsed it

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445447.htmlTechArticlephp detects whether a function exists function function_exists syntax bool function_exists (string $function_name) Check the list of defined functions, at the same time Built-in (internal) and user-defined, for...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template