ninjaneer
ninjaneer

Reputation: 7031

PHP Pathing issues

I'm a bit confused, so any answer that you can come up with that will help me get started to look where the problem is will help.

I have /folder1/API.php using: require_once('../folder2/Core.php');

I then have /folder1/Panel.php using: require_once('folder2/Core.php'); (note that there is no '..').

Somehow, both API.php and Panel.php are able to locate Core.php even though they are in the same folder but different require_once parameters.

Even weirder: in /folder2/Core.php, there's require_once('../folder3/DBConfig.php'); in which API.php is able to go through, but when calling a function from Panel.php, it says that I cannot find '../folder3/DBConfig.php'.

Upvotes: 0

Views: 89

Answers (2)

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

Keep in mind that .. say index.php includes a file test.php which is in another folder.

test.php has some includes with relative paths to other files.

Since test.php is included in index.php, all the relative paths in it will be computed relative to index.php (so most will be broken)


1 more thing:

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() /and likewise require/ will finally check in the calling script's own directory and the current working directory before failing.

Upvotes: 0

TJHeuvel
TJHeuvel

Reputation: 12608

Require (and include) will search in your include path too, perhaps the folders are included there.

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error. http://www.php.net/manual/en/function.include.php

Upvotes: 4

Related Questions