Home > Article > Backend Development > How to check if a PHP function exists?
In PHP, use the function_exists() function to check whether the function exists: it receives the function name parameter (string). Returns a Boolean value: true if the function exists, false if it does not exist.
#How to check if a PHP function exists?
In PHP, you can use the function_exists()
function to check if a function exists. This function receives one parameter, the function name (in string form), and returns a Boolean value: true
means the function exists, false
means it does not exist.
Syntax:
bool function_exists ( string $function_name )
Parameters:
Actual case:
<?php // 检查是否存在 my_function 函数 if (function_exists('my_function')) { echo 'my_function 存在'; } else { echo 'my_function 不存在'; }
Output:
my_function 不存在
Because The my_function
function has not been defined yet, so the output will be "my_function does not exist".
Note:
__autoload()
function to automatically load a function, you need to call this function before checking whether the function exists. is_callable()
function to check whether the function exists and is callable. The above is the detailed content of How to check if a PHP function exists?. For more information, please follow other related articles on the PHP Chinese website!