User login

Drupal-standard way of including files in modules

For Drupal 7, see module_load_include() and using module_load_include() for a file nested within a module directory.

At least, if we can trust the node module:

      include_once './'. drupal_get_path('module', 'node') .'/';

This was in a conditional statement, so Agaric doesn't yet know if require_once might be preferred for always-included file. We doubt it; if a file isn't included it either breaks things or it doesn't. Require guarantees PHP will come to a screeching halt.

Now, I started looking at all this because I was getting inexplicable parse errors from an include file (for instance, delete everything, still get an error on line one). The problem did not have to do with how the file was included.

Here's one of several parse errors it generated:

Parse error: syntax error, unexpected $end in /Users/ben/workspace/drupalcvs/contributions/modules/cmt/ on line 1

Here's the commit message with the, uh, fix:

that was so strange. The whole file was refusing to run; best I could determine PHP was not interpreting its spaces as spaces but running everything together. A Mac-Unix file exchange screw-up? Anyway, wasted a lot of time, used the from node module as an emptied out file and pasted my content into TextEdit, and then SubEthaEdit (TextWrangler may be the thing screwing it all up) and it works.

More accurate to say that it could not interpret line breaks as white space.

When the file consisted only of


it gave the error of no such function as "phpdebug_print_backtrace" -- at Agaric we call that a clue.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.