What happens when mymodule is enabled, but because of the registry (or even<br>in D6, the "file" argument in hook_menu()) is not loading the function you assume<br>exists just because mymodule is enabled (and module_exists('mymodule') returns<br>
TRUE?<br><br>I guess function_exists() would be path dependent now? Please correct me.<br><br><div class="gmail_quote">On Sun, Jun 22, 2008 at 5:46 PM, Larry Garfield <<a href="mailto:larry@garfieldtech.com">larry@garfieldtech.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Come Drupal 7, you'll want to use drupal_function_exists() specifically so<br>
that it can lazy-load the function if needed. I suppose that's a strike in<br>
favor of using function_exists() for now so that your logic is already setup<br>
for that.<br>
<div><div></div><div class="Wj3C7c"><br>
On Sunday 22 June 2008 4:36:46 pm Greg Knaddison - GVS wrote:<br>
> Hi,<br>
><br>
> In building some contrib modules that interact with other modules I<br>
> often find myself writing something like:<br>
><br>
> if (module_exists('module_name')) {<br>
> $foo = module_name_api_function($bar);<br>
> }<br>
><br>
> This seems to be pretty common across core and contrib. I'd even call<br>
> it standard.<br>
><br>
> Another option would be:<br>
><br>
> if (function_exists('module_name_api_function')) {<br>
> $foo = module_name_api_function($bar);<br>
> }<br>
><br>
> The benefit of the second format is that if/when module_name's<br>
> maintainer decides to rewrite module_name and change all their<br>
> functions then my module may simply stop interacting with it rather<br>
> than failing on a function not found error.<br>
><br>
> The benefit of the first format is that it fails quickly and is likely<br>
> to generate a bug report with a very clear solution.<br>
><br>
> Thoughts?<br>
><br>
> Thanks,<br>
> Greg<br>
<br>
--<br>
</div></div><font color="#888888">Larry Garfield<br>
<a href="mailto:larry@garfieldtech.com">larry@garfieldtech.com</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Khalid M. Baheyeldin<br><a href="http://2bits.com">2bits.com</a>, Inc.<br><a href="http://2bits.com">http://2bits.com</a><br>Drupal optimization, development, customization and consulting.