[development] module_exists vs. functions_exists?
winborn at advomatic.com
Wed Jun 25 15:35:37 UTC 2008
Then if developers (such as myself, but not only myself) are using
module_invoke as a safe method to invoke a module's "public" API
function, then perhaps we need to create a comparable safe and easy
method, rather than calling said developers "lazy". (The lazy method,
indeed, would be simply calling the function directly.)
Perhaps module_invoke_api or module_call_function would be in order.
As Drupal evolves, more and more modules will provide an API available
for use by other modules. In fact, there are already several such
modules, such as getID3, Voting API, and others, which do nothing but
provide glue for other modules to work with. We need to encourage this
cooperation, and if not provide an easy and safe method for invoking a
function in an API, at least document a best practice.
Earnie Boyd wrote:
> Quoting Chris Johnson <cxjohnson at gmail.com>:
>> 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
>> It will always work to call hooks, however. Hence, by definition, it is
>> wrong to use it for a purpose it was not meant.
> Correct, and stating it like Chris has said we can go as far to say
> that module_invoke is a private core function reserved for the use of
> the hooks class. Modules themselves should not use it unless the
> module has created a hook and needs to call other modules
> implementations of that hook.
> Earnie -- http://for-my-kids.com/
> -- http://give-me-an-offer.com/
More information about the development