Quoting Greg Knaddison - GVS <Greg@GrowingVentureSolutions.com>:
Hi,
In building some contrib modules that interact with other modules I often find myself writing something like:
if (module_exists('module_name')) { $foo = module_name_api_function($bar); }
This seems to be pretty common across core and contrib. I'd even call it standard.
Another option would be:
if (function_exists('module_name_api_function')) { $foo = module_name_api_function($bar); }
The benefit of the second format is that if/when module_name's maintainer decides to rewrite module_name and change all their functions then my module may simply stop interacting with it rather than failing on a function not found error.
The benefit of the first format is that it fails quickly and is likely to generate a bug report with a very clear solution.
Thoughts?
I would rather ask the interacting modules to insert a MODULE_FOO_VERSION and check for the constant being defined and defined to the version you expect. The module_exists function used with function_exists as you suggest is a good fall back for not having MODULE_FOO_VERSION. Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/