PHP Function Reference

PHP function_exists() Function



The PHP function_exists() function is used to check if the given function (both built-in and user-defined functions) is defined.

Syntax

function_exists(function)

Parameters

function Required. Specify the function name, as a string.

Return Value

Returns true if the given function exists, false otherwise.

Note: This function returns false for constructs, such as list and echo.

Example: function_exists() example

The example below shows the usage of function_exists() function.

<?php
if (function_exists('filter_list')) {
    echo "filter_list() function is available. \n";
} else {
    echo "filter_list() function is not available. \n";
}
?>

The output of the above code will be:

filter_list() function is available. 

Example: using with user-defined function

Consider one more example where this function is used with a user-defined function.

<?php
function myFunction() {
  //codes
}

if (function_exists('myFunction')) {
    echo "myFunction() function is available. \n";
} else {
    echo "myFunction() function is not available. \n";
}
?>

The output of the above code will be:

myFunction() function is available. 

❮ PHP Function Handling Reference