I was wondering when you need to use module_load_include() or require_once to include files which are located within your module.
I was wondering when you need to use module_load_include() or require_once to include files
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The key thing that the Drupal
module_load_include()function does over and above the standard PHPrequire_onceis that it references the module’s path when locating the file, usingdrupal_get_path().If you were to use
require_once, you would have to do this bit yourself.The other thing it does is check that the file exists prior to trying to include it, which is handy for avoiding fatal crashes, but rather pointless if you’re going to get one anyway when you try to call the functions you tried to include. This is handy though for allowing you to produce more meaningful errors.
At the end of the day,
module_load_include()is really just a little utility function provided by Drupal to make things slightly easier for themselves. If you know where the file is located, and you know it exists there, there’s very little need to use the Drupal function; you may just as well userequire_once.