[development] module_exists vs. functions_exists?
Aaron Winborn
winborn at advomatic.com
Mon Jun 23 14:46:47 UTC 2008
As we don't have public and private scope, I think that in practice, failing a better method, module_invoke should be the safer way to do this. In my modules, if I have functionality I don't want to expose, I prefix it with an underscore: _module_name_private_api. Thus, in my hypothetical contract, module_name_public_api would be safe to be called using module_invoke, at least within a core version, and would at least guarantee the same arguments and expected result, even if the inner codebase changed. Whereas the private function would have no such guarantee, and modules invoking it do so at the risk that the function's arguments may change, or it may even cease to exist.
Additionally, module_invoke would allow for optional dependence, which is generally where I use that anyway.
----- Original Message -----
From: "Earnie Boyd" <earnie at users.sourceforge.net>
To: development at drupal.org
Sent: Monday, June 23, 2008 8:20:29 AM GMT -05:00 US/Canada Eastern
Subject: Re: [development] module_exists vs. functions_exists?
Quoting Aaron Winborn <winborn at advomatic.com>:
> I usually use the following pattern:
>
> if (module_exists('module_name')) {
> $foo = module_invoke('module_name', 'api_function', $bar);
> }
>
I think you're correct in using this; but only for hooks. You've
stated 'api_function' when it is actually the 'hook'. And if
mymodule_myfunction isn't a hook should we be using module_invoke to do
the call? No, we should call the function directly.
Earnie -- http://for-my-kids.com/
-- http://give-me-an-offer.com/
More information about the development
mailing list