Current standard appears to be (from discussion in IRC after seeing in code):

require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'MODULE') . '/somefile.php';

Seems to make more sense it drupal_get_path() returned a path with DRUPAL_ROOT already included.

require_once drupal_get_path('module', 'MODULE') . '/somefile.php';

Comments

boombatower’s picture

Status: Active » Postponed (maintainer needs more info)

Ran into following areas I am unsure about:

form.inc

 *     'file': the path to the file containing the definitions of the
 *       'operations' and 'finished' functions, for instance if they don't
 *       reside in the original '.module' file. The path should be relative to
 *       the base_path(), and thus should be built using drupal_get_path().

locale.inc (first not only)

drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css', array('preprocess' => FALSE));

Stopped after that...perhaps we should use module_load_include() ?

dave reid’s picture

Yeah, module_load_include is a better choice in this situation since it automatically does the require_once for you as well.

boombatower’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

module_load_include() has the DRUPAL_ROOT already!

jdubbwya’s picture

There is no need to define the drupal root because it should always be the current working directory and if for some reason you need to get that for php code use

getcwd()

but if you are trying to get the directory of a current file to do an include just use the following sample it will always retrieve the current directory of the file that is being executed $dir =dirname( __FILE__ )

boombatower’s picture

#4: DRUPAL_ROOT already contains getcwd() and it seems to be the standard to place in front of all paths...although you are correct...I was not involved in that decision. I assume it was to allow the use of chdir().

gpk’s picture

@5: it was to get round the issue in shutdown functions where PHP changes the cwd (to /, I think). #259623: Broken autoloader: convert includes/requires to use absolute paths