Question

There's a little library I'm trying to plug in to my project. This lib has some includes and requires across classes, so I'm trying to set an include path for all that to work.

When trying to set an include path off a sibling branch, I run into a hiccup.

For a reference point, require('/../my/test.php') works fine.

So does

set_include_path('/../');
require_once('my/test.php');

But once I try

set_include_path('/../my/');
require_once('test.php');

I get:

Warning: require_once(one.php): failed to open stream: No such file or directory in ...

What am I missing?

Was it helpful?

Solution

Starting your paths with / means look in the root directory, so /../ is technically one directory above the root directory.

To set the include path to the parent directory of the current location, you just need ../. To make the code more portable I would suggest combining it with dirname(__FILE__) to get the absolute path of the current directory.

IE:

set_include_path(dirname(__FILE__) . '/../my/');

Note the preceding / is required in that example as dirname() does not return a trailing slash

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top