Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By leeuwnhawk on
I have two custom modules, 'moda' and 'modb'. The source code of the .module files are as follows:
moda.module
<?php
function display_this($msg)
{
return $msg;
}
modb.module
<?php
display_this('hey');
I have a function defined in moda.module, and I'm trying to call this function from within my modb.module file. However, this is the error I'm encountering:
Fatal error: Call to undefined function display_this() in /opt/lampp/htdocs/drupal/sites/all/modules/moda/moda.module on line 17
What seems to be wrong in my approach?
Comments
You never call functions
You never call functions directly in .module files, you declare functions in module files. The functions you declare are then called by Drupal hooks and stuff.
The problem is that when your modb.module file is loaded, the moda.module file is not yet loaded, so the function doesn't exist.
Try changing it to this:
hook_init() is called on page load.