User Tools

Site Tools


uphp:functions:function_exists

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
uphp:functions:function_exists [2017/04/06 12:04]
jeff removed
uphp:functions:function_exists [2021/09/13 05:57] (current)
Line 3: Line 3:
 <badge>WMPRO, WMMINI FW >= 1.887</badge> <badge>WMMEGA FW >= 2.0</badge> <badge>WMPRO, WMMINI FW >= 1.887</badge> <badge>WMMEGA FW >= 2.0</badge>
  
-Checks if a function (custom or nativeexists and returns 1 if so +Check if a function exists (native or custom)
  
 ====Description==== ====Description====
  
-<well size="sm"> +<well size="sm"><html>
-<html>+
 <span style="font-size:125%;color:green">int <span style="font-size:125%;color:green">int
-<span style="color:black"> +<span style="color:black">function_exists (
-</html> +
-[[function_exists]] ( +
-<html>+
 <span style="color:green">string <span style="color:green">string
 <span style="color:blue">$function_name <span style="color:blue">$function_name
-<span style="color:black">... ] +<span style="color:black">
-</html> +</html></well>
-</well>+
  
-====Parameters====+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 [[include|included]] files.
  
-<html><b><span style="color:blue">$function_name<span style="color:black"></b></html>:  <html><b><span style="color:green">String<span style="color:black"></b></html> containing the name of the user function to call+====Parameter====
  
-<html><b><span style="color:blue">$parameters<span style="color:black"></b></html>:  Optional parameter(s) to pass to the function+<html><b><span style="color:blue">$function_name<span style="color:black"></b>:  <b><span style="color:green">String<span style="color:black"></b> containing the name of the function to check for existence</html>
  
-====Return Value====+====Return Values====
  
-Any type depending on the way the function is defined+<html><b><span style="color:green">Integer<span style="color:black"></b></html>:  1 (true) if the function exists, 0 (false) if the function does not exist
  
-====Example====+====Examples==== 
 + 
 +===Check for the existence of the 'array_key' function (available if firmware >= 1.953)===
  
 <code php> <code php>
 <? <?
-  function my_add($x,$y) { +  $f="array_key" 
-    return $x+$y;+  if (function_exists("array_key")) { 
 +    print("The function 'array_key' is available"); 
 +  } else { 
 +    print("The function 'array_key' is NOT available");
   }   }
-  $result=call_user_func("my_add",1,3); 
-  print($result); // result is 4 
 ?> ?>
 </code> </code>
  
-====See Also====+===Load a list of custom functions and check that a function is included before calling it===
  
-[[uphp:statements:function]] - Define a function+<code php> 
 +<? 
 +  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(); 
 +  } 
 +?> 
 +</code>
  
-[[uphp:statements:return]] - Return program control to the calling module+====See Also====
  
-====Additional Information====+[[phpinfo()]] - Return information about the system [including the Firmware Version]
  
-User defined functions can take many different forms, and it is not necessary to use [[call_user_func()]] to execute function unless a direct return value is needed.+[[include()]] - Include file within the current script at the current location
  
-If used within a function, the [[uphp:statements:return]] statement immediately ends execution of the function, and returns its argument as the value of the function call.+[[call_user_func()]] - Call user defined function with optional parameters 
 + 
 +[[uphp:statements:function]] - Define a function
  
uphp/functions/function_exists.1491480291.txt.gz · Last modified: 2021/09/13 05:56 (external edit)