[development] module_exists vs. functions_exists?

Chris Johnson cxjohnson at gmail.com
Tue Jun 24 23:02:01 UTC 2008

module_invoke() is used to call core API functions in a special core API
class called hooks.  If your function is not part of the core API, then
using module_invoke to call it is misleading.  Misleading code is a
maintenance problem.  Some day, the functionality of module_invoke() may
change and not work correctly to call random contributed module functions.
It will always work to call hooks, however.  Hence, by definition, it is
wrong to use it for a purpose it was not meant.

On Tue, Jun 24, 2008 at 2:31 PM, Michael Prasuhn <mike at mikeyp.net> wrote:

> On Jun 24, 2008, at 11:32 AM, Damien wrote:
>> On Tue, Jun 24, 2008 at 7:50 PM, Michael Prasuhn <mike at mikeyp.net> wrote,
>> about module_invoke(): I don't buy it. This looks like an excellent use of
>> an existing function that does exactly what is called for. What defines a
>> 'hook' anyway? Is a function not a hook if only one module implements it?
>> Would it be such a stretch to think of every function as a hook to be
>> invoked in multiple different ways?
>> It doesn't make sense to use module_invoke() in the stated case (calling a
>> specific API function of a module). module_invoke() does not do any error
>> checking, and it does not report anything useful. You should call
>> drupal_functon_exists() directly and act accordingly in case of errors.
>> Using module_invoke() here would be bad practice at best, but could also
>> be dangerous.
> Once again, I don't buy it. If you have to switch off of whether the
> function exists, then by all means do that. But for Drupal 6 development I
> see no issue with using module_invoke. If you can't be bothered to test your
> code to make sure what it depends on is there, then your code has deeper
> issues than the method used to interface with another API.
> -Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080624/8d1ad4b9/attachment.htm 

More information about the development mailing list