PHP | function_exists() Function
The function_exists() is an inbuilt function in PHP. The function_exists() function is useful in case if we want to check whether a function() exists or not in the PHP script. It is used to check for both built-in functions as well as user-defined functions.
Syntax:
boolean function_exists($function_name)
Parameter: This function accepts a single parameter $function_name. This is the name of function that we want to search in the list of defined function. This is a string type parameter.
Return Values: This function returns a Boolean value. In case a function with the name $function_name exists it returns TRUE, otherwise it returns FALSE. This function will also return FALSE for constructs like “include_once”, “echo” etc.
Below programs illustrate the function_exists() function in PHP:
Program 1:
<?php // PHP program to illustrate function_exists() // checking if the in_array() built-in function // exists or not if (function_exists('in_array')) { echo "in_array() function is available.\n"; } else{ echo "in_array() function is not available.\n"; } ?> |
Output:
in_array() function is available.
Program 2:
<?php // PHP program to illustrate function_exists() // declaring a function named WelcomeMsg function WelcomeMsg() { echo "Welcome to GeeksforGeeks"; } // checking if the function named WelcomeMsg // exists or not if (function_exists('WelcomeMsg')) { echo "WelcomeMsg() function is available.\n"; } else{ echo "WelcomeMsg() function is not available.\n"; } ?> |
Output:
WelcomeMsg() function is available.
Reference:
http://php.net/manual/en/function.function-exists.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- D3.js | d3.map.has() Function
- PHP | ord() Function
- D3.js | d3.map.get() Function
- CSS | url() Function
- p5.js | box() Function
- D3.js | d3.sum() function
- p5.js | tan() function
- D3.js | d3.set.has() Function
- p5.js | sin() function
- D3.js | d3.min() function
- PHP | dir() Function
- p5.js | value() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



