tags:

views:

50

answers:

2

Hi,

This works :

require_once 'ModuleTest.php';

But this won't :

require_once './ModuleTest.php';

Why ? This leads to the same file ! (I am on Os X, so the file path is correct). Both files are in the same directory.

A: 

Did you switch the slash to a '\'? I think that may be the issue, but not being a OS X user, I am unsure...

DBA_Alex
I used the code that I wrote here. On OS X, this is like Unix, so no "\"
Matthieu
Oh (not sure I understood your question) : I didn't replace "/" by "\" on my system (or PHP configuration file, or anything)
Matthieu
+1  A: 

require (and include) works differently if you specify a path and if you are already in an included file.

Without the path specified, it looks firstly in the include path (ie a pre-set list of locations where include files may be), then in the path of the original script that was run, and if it doesn't find it there, it looks in the path of the current file (ie the one that is actually doing the include).

However if you specify a path, it skips the first part, and only looks at the path relative to the original script.

Therefore, if you say include('ModuleTest.php');, it will look in more locations for it than if you say include('./ModuleTest.php');.

See the documentation page for include() to see exactly what happens.

It can be confusing, and the best advice is to keep your path structure as easy to manage as possible.

Spudley
Ok but here, both files are in the same directory ! So it should work.
Matthieu