FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » about a piece of code from drupal 3.0.x
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
about a piece of code from drupal 3.0.x [message #175955] Thu, 10 November 2011 08:43 Go to next message
zhang yun is currently offline  zhang yun
Messages: 3
Registered: July 2011
Karma: 0
Junior Member
hi all
i don't understand this function .if someone help me explain it ,i
would appreciate
the code:

// invoke hook $hook of module $name with optional arguments:
function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL) {
$function = $name ."_". $hook;
if (function_exists($function)) {
return $function($a1, $a2);
}
}

what is it would return ? why write $function( $a1 , $a2);?
Re: about a piece of code from drupal 3.0.x [message #175956 is a reply to message #175955] Thu, 10 November 2011 11:54 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 10/11/2011 9:43, zhang yun escribió/wrote:
> i don't understand this function .if someone help me explain it ,i
> would appreciate
> the code:
>
> // invoke hook $hook of module $name with optional arguments:
> function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL) {
> $function = $name ."_". $hook;
> if (function_exists($function)) {
> return $function($a1, $a2);
> }
> }
>
> what is it would return ? why write $function( $a1 , $a2);?

The feature is called "variable functions" and it's explained at:

http://www.php.net/manual/en/functions.variable-functions.php

Apparently, the Drupal module API allows to implement certain
functionalities in modules by writing a function with a name in a
certain format:

modulename_hookname()

This function tests whether such function exists for a given module and
calls the function if it's available.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: about a piece of code from drupal 3.0.x
Next Topic: HELP!!! from PHP 5.16 to 5.3 Unable to load dynamic library
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 21:31:17 GMT 2024

Total time taken to generate the page: 0.02413 seconds