PHP | function_exists() Function
Last Updated :
14 Mar, 2018
The function_exists() is an inbuilt function in PHP. The function_exists() function is useful in case if we want to check whether a function() exists or not in the PHP script. It is used to check for both built-in functions as well as user-defined functions.
Syntax:
boolean function_exists($function_name)
Parameter: This function accepts a single parameter $function_name. This is the name of function that we want to search in the list of defined function. This is a string type parameter.
Return Values: This function returns a Boolean value. In case a function with the name $function_name exists it returns TRUE, otherwise it returns FALSE. This function will also return FALSE for constructs like “include_once”, “echo” etc.
Below programs illustrate the function_exists() function in PHP:
Program 1:
<?php
if (function_exists( 'in_array' ))
{
echo "in_array() function is available.\n" ;
}
else
{
echo "in_array() function is not available.\n" ;
}
?>
|
Output:
in_array() function is available.
Program 2:
<?php
function WelcomeMsg()
{
echo "Welcome to GeeksforGeeks" ;
}
if (function_exists( 'WelcomeMsg' ))
{
echo "WelcomeMsg() function is available.\n" ;
}
else
{
echo "WelcomeMsg() function is not available.\n" ;
}
?>
|
Output:
WelcomeMsg() function is available.
Reference:
http://php.net/manual/en/function.function-exists.php
Share your thoughts in the comments
Please Login to comment...