[development] module_exists vs. functions_exists?

Khalid Baheyeldin kb at 2bits.com
Sun Jun 22 22:28:43 UTC 2008


What happens when mymodule is enabled, but because of the registry (or even
in D6, the "file" argument in hook_menu()) is not loading the function you
assume
exists just because mymodule is enabled (and module_exists('mymodule')
returns
TRUE?

I guess function_exists() would be path dependent now? Please correct me.

On Sun, Jun 22, 2008 at 5:46 PM, Larry Garfield <larry at garfieldtech.com>
wrote:

> Come Drupal 7, you'll want to use drupal_function_exists() specifically so
> that it can lazy-load the function if needed.  I suppose that's a strike in
> favor of using function_exists() for now so that your logic is already
> setup
> for that.
>
> On Sunday 22 June 2008 4:36:46 pm Greg Knaddison - GVS wrote:
> > 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?
> >
> > Thanks,
> > Greg
>
> --
> Larry Garfield
> larry at garfieldtech.com
>



-- 
Khalid M. Baheyeldin
2bits.com, Inc.
http://2bits.com
Drupal optimization, development, customization and consulting.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080622/8a1eb362/attachment-0001.htm 


More information about the development mailing list