Table of Contents

function_exists

WMPRO, WMMINI FW >= 1.887 WMMEGA FW >= 2.0

Check if a function exists (native or custom)

Description

int function_exists ( string $function_name )

This function will check to see if a function exists in firmware (native, internal) or has been defined in the current script context (custom, user-defined). It is useful if a script needs to determine if it is being run on an older version of the firmware that might not have some of the newer functions. It can also be used for controlling flow in scripts that define custom functions depending on certain conditions or included files.

Parameter

$function_name: String containing the name of the function to check for existence

Return Values

Integer: 1 (true) if the function exists, 0 (false) if the function does not exist

Examples

Check for the existence of the 'array_key' function (available if firmware >= 1.953)

<?
  $f="array_key"
  if (function_exists("array_key")) {
    print("The function 'array_key' is available");
  } else {
    print("The function 'array_key' is NOT available");
  }
?>

Load a list of custom functions and check that a function is included before calling it

<?
  include("/my_functions.inc");
 
  $f="my_function_number_23";
  if (function_exists($f)) {
    print(call_user_func($f,1,3));
  } else {
    print("Error: '/my_functions.inc' does not include function '".$f."'");
    die();
  }
?>

See Also

phpinfo() - Return information about the system [including the Firmware Version]

include() - Include a file within the current script at the current location

call_user_func() - Call a user defined function with optional parameters

function - Define a function