If compatibility with various PHP versions is especially important to your script, it’s useful to be able to check for the existence of functions. The function function_ exists does just what you’d expect. It takes a string with a function’s name and returns TRUE or FALSE depending on whether the function has been defined. For example, the following code tests a function:
This code displays the following:
Function test_this does not exist.
The Function test_this does not exist message displays because you haven’t defined the function test_this.
<?php
$test=function_exists("test_this");
if ($test == TRUE)
{
echo "Function test_this exists.";
}
else
{
echo "Function test_this does not exist.";
//call_different_function( );
}
?>
This code displays the following:
Function test_this does not exist.
The Function test_this does not exist message displays because you haven’t defined the function test_this.