Skip to content
WJunction - Webmaster Forum

Testing a Function in PHP??

Status
Not open for further replies.
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:

<?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.
 
Status
Not open for further replies.

About the author

chinmay
Banned · Joined
17
Messages
0
Reactions
1
Points

Tags

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom