I'm familiar with using
module_exists in a module, and using it in situations like:
- Enable some extra functionality in a module, provided some other module is available in the site also. The Reservations: Email module contains an example (actually there are plenty of examples of this), as shown in its module source: to use tokens (in the eMail body) requires that the Token module is enabled.
- Implement module dependencies in a theme, as shown in the answer to "How to implement module dependencies in a theme and package modules with a theme?".
However, there is also
I have the impression that using
function_exists is a more robust (safe) approach as compared to
module_exists. Especially if you want to be sure that some function (added in a newer version of a module) is available, whereas by just using
module_exists, you risk to run into errors like those:
- if a site is still using an old version of a module, which doesn't have that function yet (so you shouldn't try to use it yet).
- if a site is already using an new version of a module, which doesn't have that function anymore (so you shouldn't try to use it anymore).
My question: what are the typical criteria, or pros/cons, to decide for using either