I've had a few modules which have been kicking up a stink under php 5, namely (so far) pathauto and print (see here, across different releases of core.

Basically, I get a lot of "errors: open_basedir restriction in effect" kind of errors. I hunted around and found a fix that seems to work across the board with my current setup. Changing the way the include is performed seems to stop the errors.

However, I have no idea if I'm breaking Drupal protocol, or using out of date functionality, or anything, so I throw myself upon your mercy to clarify the matter, good people! :)

I'm currently changing code that reads similar to this from:

include_once('print.node.tpl.php');

to:

include_once(drupal_get_path('module', 'print') .'/print.node.tpl.php');

If anyone can shed some light on whether or not this is correct or really bad for some reason, that would be most appreciated.

Happy holidays to all :)

Comments

agentrickard’s picture

The corrected code you suggest is 'better code,' because it uses Drupal's built-in functions to locate the file for you.

My suspicion is that the relative path in the first example fails, since PHP doesn't know what directory to look in. When the second code string is executed, you end up with something like this:

 include_once('/sites/default/all/modules/print/print.node.tpl.php');

You should probably file bug reports for the affected modules, since Drupal modules should never be using relative paths to make include calls.

--
http://ken.blufftontoday.com/
http://new.savannahnow.com/user/2
Search first, ask good questions later.

niklp’s picture

This pleases me greatly...! :)

Weird though, as this latest example was from a very recently ported-to-5 module! Will report bugs where and when appropriate then.

Is there any example of circumstances where this [edit: the aforementioned, incorrect] code would either be appropriate or necessary?

agentrickard’s picture

Not that I can think of. The only possible exception would be an include file called by a theme file from within the same directory.

e.g. node.tpl.php calls include_once(helper.tpl.php).

The drupal_get_path() function is there to ensure that file paths are called consistently.

--
http://ken.blufftontoday.com/
http://new.savannahnow.com/user/2
Search first, ask good questions later.

penups’s picture

"Is there any example of circumstances where this [edit: the aforementioned, incorrect] code would either be appropriate or necessary?"
I would like to know this too. I dont think its possible but not really sure.

agentrickard’s picture

I'm 95% sure the answer is "no." You can never be sure what include path a user's php will use. That's why drupal_get_path() exists.

--
http://ken.blufftontoday.com/
http://new.savannahnow.com/user/2
Search first, ask good questions later.

niklp’s picture

I've patched about 7 modules with that code (including pathauto, weee!) with no ill effects - it's just a "hangover" from v4 methinks.

kvazipatak’s picture

I see. Its quite logical now when you put it that way.
Thanks for the explanation anyway mate.