The php Function Function Exists
The php function function_exists checks whether a particular function (either built-in or one you've defined yourself) is available for use. Specifically, it takes the name of the function as its only parameter, and it returns true if the function exists, and false otherwise.
Aside from the function_exists() function, there are a number of other functions in PHP that are related to function checking. The class_exists() function is for checking if a specific type of object or class is present, while the method_exists() function is used to check for methods in a particular object or class instance.
Function checks are commonly employed in Model-View-Controller frameworks in order to ensure that a given method is available before calling it. For example, when writing a class that implements an MVC pattern, you would check that the class has the posts and edit methods using the function_exists() function.
Note that the function_exists() function only checks if the specified function actually exists in the current environment; it does not verify that the function will work as it may not be available for use due to a variety of reasons, such as configuration and compiling options. For this reason, it's best to use a debugger integrated with your IDE to help you verify that the functions you are trying to call are available and will actually work.
Learn more about coding in PHP and other skills for becoming a full stack web developer in our free, self-paced course. Get started today.